Django 管理 TemplateSyntaxError / TemplateDoesNotExist 位于 /admin/
我刚刚将 django 更新到版本 1.2.4,但是,在采取了安装管理程序的正常步骤后,我收到了 TemplateSyntaxError:
TemplateSyntaxError at /admin/
Caught TemplateDoesNotExist while rendering: admin/base.html
So a superuser has been Created, I've安装了应用程序,运行了syncdb。我的网址页面如下:
[...]
# 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/', include(admin.site.urls)),
[...]
此外,如果我遵循管理媒体的路径,例如 http://localhost:8000/static/admin/css/base.css
我得到:权限被拒绝:/static/admin/css/base.css
- 修复了这个问题,但加载管理时仍然出现相同的错误
更新
确定,所以现在可以通过将我的正常模板目录中的管理模板..但我认为这是一个坏主意,但这可能意味着它可能只是权限或路径的问题?
更新
这可能是权限问题吗?我想要 CHMOD 这些来做什么?
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...]
问题已修复
涉及重新安装 django 并启动一个新项目。虽然结果不太令人满意,但还是感谢您的帮助!
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/', include(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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查
django.contrib.admin
是否已添加到INSTALLED_APPS
设置中。如果不存在,则管理模板目录django/contrib/admin/templates
将不会添加到模板目录列表中,并且您将获得TemplateDoesNotExist< /代码> 错误。
此外,请确保将
django.template.loaders.app_directories.Loader
添加到TEMPLATE_LOADERS
设置中。这是实际的加载程序,它知道任何已安装应用程序包根目录中的任何templates/
目录都应该用于模板发现。Check that
django.contrib.admin
is added in theINSTALLED_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 theTemplateDoesNotExist
error.Additionally, make sure the
django.template.loaders.app_directories.Loader
is added toTEMPLATE_LOADERS
settings. That's the actual loader that knows that anytemplates/
directory in the root of any installed application package should be used for template discovery.通常在 django 中,js 脚本或 css 等静态文件和图像由不同的处理程序提供。您似乎没有提供以“^static”开头的 URL,那么应用程序可能找不到它们。
我建议您在 url.py 中添加一行:
并尝试从其 URI 访问 CSS。如果您能够这样做,那么模板也应该正确呈现。
...但同样,错误表明模板渲染错误。您是否遵循基本安装程序?
http://docs.djangoproject.com/en/1.2/intro/tutorial02/
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:
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/
这意味着您错过了前面概述的先决条件:没有安装 docutils 软件包
,或者该
软件包没有添加到
settings.py 中的
。INSTALLED_APPS
变量this means you missed a prerequisite outlined earlier: either the docutils package wasn't installed with
or the
package wasn't added to the
INSTALLED_APPS
variable insettings.py
.