0

我有一个具有下一个文件夹结构的 django 项目:

+ project
+ - - app_1
+ - - - - __init__.py
+ - - - - models.py
+ - - - - forms.py
+ - - - - urls.py
+ - - - - templates
+ - - - - - - index.html
+ - - - - - - edit.html
+ - - - - - - show.html
+ - - - - views
+ - - - - - - __init__.py
+ - - - - - - index.py
+ - - - - - - edit.py
+ - - - - - - show.py
+ - - - - - - templatetags
+ - - - - - - - - __init__.py
+ - - - - - - - - custom_tags.py

例如,当我尝试在 edit.html 模板中调用 custom_tags

{% load custom_tags %}

我得到下一个错误:

/app_1/ 处的 TemplateSyntaxError

“custom_tags”不是有效的标签库:找不到模板库 custom_tags

我的问题是:我需要在哪里放置 templatetags 文件夹或我需要做什么?

谢谢。

4

2 回答 2

2

尝试将你的 templatetags 目录向上移动一级,到你的 app_1 目录下(如https://docs.djangoproject.com/en/dev/howto/custom-template-tags/)。

于 2013-11-20T04:33:19.597 回答
0

templatetags 文件夹应该在 app 文件夹中:

+ project
+ - - app_1
+ - - - - __init__.py
+ - - - - templatetags
+ - - - - - - __init__.py
+ - - - - - - custom_tags.py

根据您的服务器,您可能需要重新启动它。

于 2013-11-20T04:40:38.170 回答