Admin Site: TemplateDoesNotExist at /admin/

前端 未结 16 1861
鱼传尺愫
鱼传尺愫 2020-12-09 04:00

I\'m following Django\'s official Tutorial 2 but for some reason cannot create an admin site despite following all the steps correctly to my understanding.

This is t

16条回答
  •  难免孤独
    2020-12-09 04:32

    I am using Django Version 1.9.7 and when trying to add the admin_tools (menu and dashboard) to my application I had a similar issue. I found I had to do three things:

    1. Edit the INSTALLED_APPS option in settings.py as follows (note that the admin_tools come before django contrib, 'mines' is the name of my application):

      INSTALLED_APPS = [
          'admin_tools',
          'admin_tools.theming',
          'admin_tools.menu',
          'admin_tools.dashboard',
          'django.contrib.admin',
          'django.contrib.auth',
          'django.contrib.contenttypes',
          'django.contrib.sessions',
          'django.contrib.messages',
          'django.contrib.staticfiles',
          'mines'
      ]
      
    2. Edit the TEMPLATE setting in the settings.py file as follows (note the 'loaders' option that got added, and that APP_DIRS are now set to false):

      TEMPLATES = [{
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [],
          'APP_DIRS': False,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
              'loaders': [
                  'django.template.loaders.filesystem.Loader',
                  'django.template.loaders.app_directories.Loader',
                  'admin_tools.template_loaders.Loader',
              ],
          },
      }]
      
    3. And then finally I updated my urls.py file as follows (note the include for the admin_tools urls):

      from django.conf.urls import include,url
      from django.contrib import admin
      from mines.views import SummaryByMapIcon
      
      urlpatterns = [
          url(r'^admin_tools/', include('admin_tools.urls')),
          url(r'^admin/', admin.site.urls),
          url(r'^summarybymapicon$', SummaryByMapIcon, name='summarybymapicon'),
      ]
      

提交回复
热议问题