Admin Site: TemplateDoesNotExist at /admin/

前端 未结 16 1781
鱼传尺愫
鱼传尺愫 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'),
      ]
      
    0 讨论(0)
  • 2020-12-09 04:33

    I'm adding an "answer" as I cannot with my current "reputation" add a comment.

    Following Aaron solution:

    In a project with Django 1.4 with docker with the same issue (accessing yourproject/admin/login.html or yourproject/admin/index.html). I used in python.dockerfile this, and solved:

    "RUN pip install -r requirements.txt --no-cache-dir"
    

    Before I did this, I verified entering inside the docker, that inside the folder usr/local/lib/python2.7/site-packages/django/contrib/admin/ didnt exist the folder /templates/.

    I was reading this before coming to this post: https://www.mail-archive.com/search?l=django-users@googlegroups.com&q=subject:%22TemplateDoesNotExist+at+%5C%2Fadmin%5C%2F%22&o=newest&f=1

    0 讨论(0)
  • 2020-12-09 04:36

    I solved this same problem by reinstalling Django with the --no-cache-dir option:

    pip uninstall django
    pip install django --no-cache-dir
    

    Solved thanks to the answer here.

    0 讨论(0)
  • 2020-12-09 04:36

    Had the same issue. Strangely I found that sometime the template and media is not copied from your django/contrib/admin. Therefore you need to copy them to your virtual env django directory.

    i.e from your /venv/lib/python2.7/site-packages/django/contrib directory you need to

    ln -s ~/Sites/your_dj_app/venv/django/contrib/admin/templates templates

    and

    ln -s ~/Sites/your_dj_app/venv/django/contrib/admin/media media

    I am so glad that my problem is solved but so annoyed that I had to spend over an hour debugging it.

    Hope you won't have to :)

    0 讨论(0)
提交回复
热议问题