The Django Admin site is a built-in app that allows direct access to data in our database as soon as a model has been migrated. To enable the admin site we have to update the settings file to include the following:
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [Path(__file__).parent / "templates"],
"APP_DIRS": True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }
]
INSTALLED_APPS=[
"blogs",
"django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", 'django.contrib.sessions', "django.contrib.messages", "django.contrib.staticfiles",
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
]
DATABASES={
...
}
DEFAULT_AUTO_FIELD="django.db.models.BigAutoField"
STATIC_URL="static/"These are the more or less the standard options that come by default in Django.
Creating a superuser
Once the admin site is in place we can create an administrator account with the following:
python manage.py createsuperuserTemplates
In TEMPLATES we set APP_DIRS to True because the built-in pages for the admin views are stored in the admin app. True, then, tells Django to look for templates in our main templates directory as well as other directories named templates in each app’s folder.
Because the admin area requires authorization, we also include some Django Context Processors to prevent unauthorized access.
Installed Apps
The additions to INSTALLED_APPS are more built-in apps that are used to manage auth, the admin site, types of content, and a few other things.