Enable Django Admin site.

The following are the pre-requisites to enabling the django admin site (http://localhost:8000/admin):
  1. Absence of requisite tables in database and pending migrations: When you have a newly created Django website, or, when you change to a new database engine, you need to ensure that you've completed the migrations and that the requisite tables (the ones with auth_ prefix) are available in the database. To perform the requisite migrations, run the following command:
    python manage.py migrate
  2. Existence of a superuser: If you have a newly created website, and you haven't create a superuser yet, you won't be able to access the admin site. Django creates the admin site for you when you create a superuser.
  3. Absence of requisite URL redirection in urls.py: Your urls.py needs to have the following basic minimum code to be able to redirect you to django admin site:
    from django.contrib import admin
    from django.urls import path
    urlpatterns = [
          path('admin/', admin.site.urls)
    ]


Comments