Django admin TemplateSyntaxError / TemplateDoesNotExist at /admin/
I've just updated django to version 1.2.4 but, having taken the normal steps with installing the admin, i'm getting a TemplateSyntaxError:
TemplateSyntaxError at /admin/
Caught TemplateDoesNotExist while rendering: admin/base.html
So a superuser has been created, i've installed the app, run syncdb. My urls page is as follows:
[...]
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# admin enabled
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', incl开发者_Python百科ude(admin.site.urls)),
[...]
In addition if I follow the paths for the admin media e.g. http://localhost:8000/static/admin/css/base.css
I get: Permission denied: /static/admin/css/base.css
- fixed this, but same error loading admin remains
Update
OK so it now works, by putting the admin templates inside my normal template dir.. but I assume this is a bad idea, but it perhaps implies it might simply be an issue with permissions or paths?
Update
Could this be a permissions issue? What would I want to CHMOD these to?
pwd /Library/Python/2.6/site-packages/django/contrib/admin/templates/admin
Adam-Gambles-MacBook-Air:admin adamgamble$ ls -al
total 168
drwxr-xr-x 26 root admin 884 17 Mar 12:27 .
drwxr-xr-x 4 root admin 136 17 Mar 12:27 ..
-rw------- 1 root admin 268 18 Mar 2008 404.html
-rw------- 1 root admin 502 18 Mar 2008 500.html
-rw------- 1 root admin 1095 4 May 2010 actions.html
-rw------- 1 root admin 347 23 Aug 2008 app_index.html
drwxr-xr-x 3 root admin 102 17 Mar 12:27 auth
-rw------- 1 root admin 3605 10 Oct 02:59 base.html
[...ETC...]
PROBLEM FIXED
Involved reinstalling django, and starting a new project. Dissatisfying result, but thanks for helping out!
Check that django.contrib.admin
is added in the INSTALLED_APPS
settings. If it's not there, then the admin templates directory, django/contrib/admin/templates
, won't be added to the list of template directories, and you'll be getting the TemplateDoesNotExist
error.
Additionally, make sure the django.template.loaders.app_directories.Loader
is added to TEMPLATE_LOADERS
settings. That's the actual loader that knows that any templates/
directory in the root of any installed application package should be used for template discovery.
Usually in django static files like js scripts or css and images are served by a different handler. It seems you did not served the URLs that starts with '^static' then the application may not find them. I advise you serve them with an additional line in the url.py:
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/path/to/static/files'}),
And try to access the CSS from its URI. If you're able to do so, then also the template should be correctly rendered.
... but again, the error says template rendering error. Did you follow the base installation procedure? http://docs.djangoproject.com/en/1.2/intro/tutorial02/
TemplateDoesNotExist at /admin/doc/
this means you missed a prerequisite outlined earlier: either the docutils package wasn't installed with
pip install docutils
or the
django.contrib.admindocs
package wasn't added to the INSTALLED_APPS
variable in settings.py
.
精彩评论