gpt4 book ai didi

Python Django 自定义模板标签 register.assignment_tag 不工作

转载 作者:太空狗 更新时间:2023-10-29 21:13:47 25 4
gpt4 key购买 nike

这是我的 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. The simple_tag() helper has gained this same ability, making the assignment_tag obsolete. Tags that use assignment_tag should be updated to use simple_tag.

请注意,simple_tag 的行为与 Django 1.8 中的 assignment_tag 相似但不完全相同。

关于Python Django 自定义模板标签 register.assignment_tag 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21021690/

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