简体   繁体   English

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

[英]How come I'm getting this Django error?

I installed an app called Django-notification, which uses Django-pagination. 我安装了一个名为Django-notification的应用程序,该应用程序使用Django-pagination。 However, it can't find the Django_pagination template tags! 但是,它找不到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

Why? 为什么? I installed Django-pagination already. 我已经安装了Django-pagination。 It's in my site-packages: django_pagination-1.0.7-py2.6.egg 在我的站点包中: django_pagination-1.0.7-py2.6.egg

Next, I put "pagination" in my INSTALLED_APPS. 接下来,在我的INSTALLED_APPS中放入“分页”。

I even imorted pagination in my views.py. 我什至在我的views.py中也增加了分页功能。 Although I doubt that'll make a difference. 尽管我怀疑这会有所作为。

Just to make sure, have you called {% load pagination_tags %} in your template? 只是为了确保您是否在模板中调用了{% load pagination_tags %}

From django's documentation : django的文档中

The app that contains the custom tags must be in INSTALLED_APPS in order for the {% load %} tag to work. 包含自定义标记的应用程序必须位于INSTALLED_APPS中,才能使{%load%}标记起作用。 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. 这是一项安全功能:它允许您在单个主机上托管许多模板库的Python代码,而无需为每个Django安装启用对所有模板库的访问。

There's no limit on how many modules you put in the templatetags package. 放入templatetags包中的模块数量没有限制。 Just keep in mind that a {% load %} statement will load tags/filters for the given Python module name, not the name of the app. 请记住,{%load%}语句将为给定的Python模块名称而不是应用程序名称加载标签/过滤器。

To be a valid tag library, the module must contain a module-level variable named register that is a template.Library instance... 要成为有效的标签库,模块必须包含一个名为register的模块级变量,该变量是一个模板。库实例...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM