I'm trying to make a batch file that runs syncdb to create a database file, and then create a superuser with the username "admin" and the password "admin".
My code so far:
python manage.py syncdb --noinput
python manage.py createsuperuser --username admin --email [email protected]
python manage.py runserver
Now this prompts me to enter a password and then confirm the password. Can I enter this information with a command from the same batch file, another batch file, or is this just not possible?
Type python3 manage.py createsuperuser in the given terminal and press “Enter”. The system will ask for credentials, after which a superuser will be created. To run the server, we type the command python3 manage.py runserver 0.0. 0.0:8000 and press “Enter”.
when you run python manage.py runserver, it will take 127.0. 0.1 as default ip address and 8000. 127.0. 0.0 is the same as localhost which can be accessed locally. to access it from cross origin you need to run it on your system ip or 0.0.
It is not possible to uninstall superuser directly from uninstaller because superuser is the main control app of your root files and access. But you can remove it by Factory reseting your phone ( make sure you backup all your apps and settings before doing so.) Factory reseting will default all your files and apps.
As it seems you can't provide a password with the echo ''stuff | cmd
, the only way I see to do it is to create it in Python:
python manage.py syncdb --noinput
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '[email protected]', 'pass')" | python manage.py shell
python manage.py runserver
As of Django 3.0 (per the docs) you can use the createsuperuser --no-input
option and set the password with the DJANGO_SUPERUSER_PASSWORD
environment variable, e.g.,
DJANGO_SUPERUSER_PASSWORD=my_password ./manage.py createsuperuser \
--no-input \
--username=my_user \
[email protected]
or, using all environment variables:
DJANGO_SUPERUSER_PASSWORD=my_password \
DJANGO_SUPERUSER_USERNAME=my_user \
[email protected] \
./manage.py createsuperuser \
--no-input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With