- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我的 Python Django 自定义模板标签代码
from django import template
from ipc.declarations.models import MainDeclaration
from django.shortcuts import get_object_or_404
register = template.Library()
def section_settings(declarationId,user):
declaration = get_object_or_404(MainDeclaration, pk=declarationId, user=user)
businessInfo = declaration.GetOrCreateBusinessInfo()
sections = declaration.GetSections()
return sections
register.assignment_tag(section_settings)
现在我得到一个错误
register.assignment_tag(section_settings)
[2014 年 1 月 9 日星期四 06:50:44] [错误] [客户端 127.0.0.1] AttributeError:“库”对象没有属性“assignment_tag”
这适用于我的开发服务器应用程序,但在生产服务器中上传相同代码时无法正常工作。
请指导我。
最佳答案
尽管这个问题已经有几年了,但人们最近可能会再次看到这个错误,但原因不同。又是这个错误:
AttributeError: 'Library' object has no attribute 'assignment_tag'
升级到 Django 2.0 后,您可能会看到此错误。这是因为 assignment_tag
was deprecated in Django 1.9 ,并在 Django 2.0 中删除:
Django 1.4 added the
assignment_tag
helper to ease the creation of template tags that store results in a template variable. Thesimple_tag()
helper has gained this same ability, making theassignment_tag
obsolete. Tags that useassignment_tag
should be updated to usesimple_tag
.
请注意,simple_tag
的行为与 Django 1.8 中的 assignment_tag
相似但不完全相同。
关于Python Django 自定义模板标签 register.assignment_tag 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21021690/
我正在使用 Django 开发一个项目。 今天早些时候,我发现了新的 (Django >= 1.4) assignment_tag。我立即决定这正是我在任何地方都需要的东西,并将一些逻辑放入一个对数据
这是我的 Python Django 自定义模板标签代码 from django import template from ipc.declarations.models import MainDec
我是一名优秀的程序员,十分优秀!