我在 Django 应用程序中有一些模板标签,对于不同的标签/模板具有相同的功能。
foo 标签转到 foo_template.html,boo 标签转到 boo_template.html,例如:
富标签:
@register.inclusion_tag('foo_template.html', takes_context=True)
def foo(context, something):
sometng = something
return {'something': sometng}
嘘标签:
@register.inclusion_tag('boo_template.html', takes_context=True)
def boo(context, something):
sometng = something
return {'something': sometng}
我怎样才能使我的代码干燥?在这种情况下是否有更好的方法来注册标签?