1.

How to create a superuser in Django?

Answer»

Django has only one USER type that is User. USERS are differentiated on the basis of permissions you give. Any normal user can be authenticated and any user assigned the staff flat can log in to the contributed admin APP. Users can be set active or de-active and only active users are allowed to log in. A SUPERUSER is just a convenient method to create a user with all permissions. 

In Django, you easily create a superuser account to access the admin site. 

We are assuming here that the project is created and database connection is set up, and you are in a project folder.

Now create an application by executing the command -

$ python manage.py startapp newapp

Register your newapp with the Django project say 'newproject'. Open settings.py in the code editor and update INSTALLED_APPS TUPLE and middleware tuple. 

//settings.py INSTALLED_APPS = (    'django.contrib.admin',    'django.contrib.auth',    'django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'django.contrib.staticfiles',    'newapp', ) MIDDLEWARE_CLASSES = (    'django.contrib.sessions.middleware.SessionMiddleware',    'django.middleware.common.CommonMiddleware',    'django.middleware.csrf.CsrfViewMiddleware',    'django.contrib.auth.middleware.AuthenticationMiddleware',    'django.contrib.messages.middleware.MessageMiddleware',    'django.middleware.clickjacking.XFrameOptionsMiddleware', )

Now to access Admin Interface, initiate database by executing commands -

$ python manage.py makemigrations $ python manage.py migrate

Now create superuser by executing the command -

$ python manage.py createsuperuser

Wait for the success message and then enter the remaining user information.



Discussion

No Comment Found