Search code examples
djangobatch-filecmdcommand-prompt

Django create superuser from batch file


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?


Solution

  • 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