Django include找不到temp

2024-07-07 08:23:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我想包括评论.html“进入存储.html以及存储.html延伸基本.html. 在

但是Django抛出错误comment.html (<class 'django.template.base.TemplateDoesNotExist'>)

所有模板都在同一个目录中。store.html工作正常,并且它没有任何错误地正确地扩展{}问题。但是当我在store.html中包含comment.html时,会抛出错误。。。 我使用了{% include "comment.html" %}这将comment.html包含到store.html

这些文件所在的目录树: 瓦布哈夫@ubuntu:~/TRAC/bright coupons/brightCouponsApp$tree . 在

├── __init__.py
├── models.py
├── templates
│   ├── about.html
│   ├── base.html
│   ├── comment.html
│   ├── contact.html
│   ├── error.html
│   ├── index.html
│   ├── index-var.html
│   ├── store.html
│   ├── stores.html
│   ├── submit-form.php
│   ├── support.html
│   └── tags.html
├── tests.py
├── views.py

Tags: djangostorepy目录模板baseindexhtml
1条回答
网友
1楼 · 发布于 2024-07-07 08:23:42

请注意,当您确实包含到时,您必须将路径相对于模板目录的根目录。所以如果评论.html驻留在模板_BASE_DIR/app中/评论.html你必须这么做

{% include "app/comments.html" %}

路径与包含模板的位置无关(因为包含模板可能是字符串…)

相关问题 更多 >