python - 我怎么会收到这个 Django 错误?

标签 python django templates pagination

我安装了一个名为 Django-notification 的应用程序,它使用 Django-pagination。但是,它找不到 Django_pagination 模板标签!

Exception Type: TemplateSyntaxError at /notifications
Exception Value: 'pagination_tags' is not a valid tag library: Template library pagination_tags not found, tried django.templatetags.pagination_tags,django.contrib.admin.templatetags.pagination_tags,django.contrib.humanize.templatetags.pagination_tags,pinax.templatetags.templatetags.pagination_tags
为什么?我已经安装了 Django 分页。它在我的站点包中:django_pagination-1.0.7-py2.6.egg

接下来,我将“分页”放入 INSTALLED_APPS 中。

我什至在我的views.py 中添加了分页。尽管我怀疑这会有所作为。

最佳答案

为了确定,您是否在模板中调用了 {% load pagination_tags %}

来自django's documentation :

The app that contains the custom tags must be in INSTALLED_APPS in order for the {% load %} tag to work. This is a security feature: It allows you to host Python code for many template libraries on a single host machine without enabling access to all of them for every Django installation.

There's no limit on how many modules you put in the templatetags package. Just keep in mind that a {% load %} statement will load tags/filters for the given Python module name, not the name of the app.

To be a valid tag library, the module must contain a module-level variable named register that is a template.Library instance...

关于python - 我怎么会收到这个 Django 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4631820/

相关文章:

python - 使用 django-filter 时在 Django 中向表单添加占位符

python - 将函数传递给类

python - "no such table"异常

css - MailChimp 白色文本模板问题

c++ - 如何在任意依赖类型上专门化模板

python - 如何使用groupby中的两个组计算百分比?

python - 使用补丁自定义散点图中的图例标记面部颜色

python - Django 没有名为 django.core.management 的模块

Django 模板用户请求

templates - 在Liquid模板中输出文字大括号