gpt4 book ai didi

python - 在 Django 中使用 templatetags 时导入错误

转载 作者:行者123 更新时间:2023-12-01 06:16:58 26 4
gpt4 key购买 nike

嗯,当我尝试在 Django 中使用“包含”时,我遇到了一些我自己无法解决的困惑问题。

这是我的项目的结构。

MyProject---
App1---
__init__.py
models.py
test.py
urls.py
views.py
App2---
...
template---
App1---
some htmls
App2---
...
templatetags---
__init__.py
inclusion_cld_tags.py
manage.py
urls.py
__init__.py
settings.py

我已在 settings.py 中注册了 templatetags 文件夹(均在已安装的应用程序和 TEMPLATE_DIRS 中)。但是当我想在我的 html 中使用 {% loadclusion_test %} 时,它会引发如下异常:

'inclusion_cld_tags' is not a valid tag library: Could not load template library from django.templatetags.inclusion_cld_tags, No module named inclusion_cld_tags

我认为我的导入工作没有任何问题,我该怎么办?

感谢您的帮助!

我的 django 版本:1.0+我的Python版本:2.6.4

最佳答案

  1. templatetags 文件夹 should live in the app folder :

            App1---
    __init__.py
    models.py
    test.py
    urls.py
    views.py
    templatetags---
    __init__.py
    inclusion_test.py
    ...
  2. 您注册了该标签吗?

示例:

register = template.Library()   
@register.inclusion_tag('platform/templatetags/pagination_links.html')
def pagination_links(page, per_page, link):

关于python - 在 Django 中使用 templatetags 时导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2771850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com