Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admin Site: TemplateDoesNotExist at /admin/

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 the error I get:

TemplateDoesNotExist at /admin/
admin/login.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version: 1.3.1
Exception Type: TemplateDoesNotExist
Exception Value:    
admin/login.html
Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader.py in find_template, line 138
Python Executable:  /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.2
Python Path:    
['/Users/jcugley/Documents/Programming/Python/Django/mysite',
 '/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
 '/Library/Python/2.7/site-packages']
Server time:    Tue, 24 Jan 2012 18:40:03 -0600

The error occurs after I uncomment the following lines (commented):

### urls.py ###
from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin # THIS LINE
admin.autodiscover() # THIS LINE

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)), # THIS LINE
)

If I comment them again it gets rid of the error.

I do have django.contrib.admin in my INSTALLED_APPS in settings.py

like image 772
Jarrod Avatar asked Jan 25 '12 00:01

Jarrod


3 Answers

I ran into the same problem, and I had to force pip to re-download django.

pip install -r requirements.txt --ignore-installed --force-reinstall --upgrade --no-cache-dir 

Note: I know that the --no-cache-dir option is necessary, I'm not certain that the other options are all required.

like image 77
Aaron Avatar answered Sep 22 '22 05:09

Aaron


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.

like image 21
Konstantin Avatar answered Sep 19 '22 05:09

Konstantin


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'),
    ]
    
like image 35
Abrie Nel Avatar answered Sep 21 '22 05:09

Abrie Nel