Django 管理 TemplateSyntaxError / TemplateDoesNotExist 位于 /admin/

发布于 2024-10-23 12:23:33 字数 1612 浏览 4 评论 0原文

我刚刚将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

佼人 2024-10-30 12:23:33

检查 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 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.

錯遇了你 2024-10-30 12:23:33

通常在 django 中,js 脚本或 css 等静态文件和图像由不同的处理程序提供。您似乎没有提供以“^static”开头的 URL,那么应用程序可能找不到它们。
我建议您在 url.py 中添加一行:

(r'^static/(?P<path>.*)

并尝试从其 URI 访问 CSS。如果您能够这样做,那么模板也应该正确呈现。

...但同样,错误表明模板渲染错误。您是否遵循基本安装程序?
http://docs.djangoproject.com/en/1.2/intro/tutorial02/

, 'django.views.static.serve', {'document_root': '/path/to/static/files'}),

并尝试从其 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:

(r'^static/(?P<path>.*)

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/

, '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/

风铃鹿 2024-10-30 12:23:33

TemplateDoesNotExist 位于 /admin/doc/

这意味着您错过了前面概述的先决条件:没有安装 docutils 软件包

pip install docutils

,或者该

django.contrib.admindocs

软件包没有添加到 settings.py 中的 INSTALLED_APPS 变量

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文