[Django]-How to create a superuser in Django with Linux shell script?

11👍

Rather than use the createsuperuser management command you can provide a fixture.

You’ll need to provide a fixture for the auth.user model. For the password you can generate one via the Django shell

>>> from django.contrib.auth.hashers import make_password
>>> make_password('password')

Your final fixture should look like:

[
    { "model": "auth.user",
        "pk": 1,
        "fields": {
            "username": "admin",
            "password": "<output of make_password()>"
            "is_superuser": true,
            "is_staff": true,
            "is_active": true
        }
    }
]

Leave a comment