Everything you need to get started with Django admin is already setup in Django's default project layout. This includes:
# settings.py
# `django.contrib.admin` and its dependancies.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
...,
]
MIDDLEWARE = [
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
...
]
TEMPLATES = [
{
...,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
...
],
},
},
]
Be careful about urls.py
that is slightly different in Django >= 1.9 than in older versions.
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]
Version with include
will still work in Django 1.9 but is deprecated and will be removed in the future.
If not already done, you must apply the base migrations:
$ python manage.py migrate
To access the admin, you also have to create a superuser with:
$ python manage.py createsuperuser
Once this is done, you can run your server:
$ python manage.py runserver
And visit the admin page at http://127.0.0.1:8000/admin/