如何从普通函数调用django模板标签?
例如:
Django模板标签:
@register.filter(name='CallingTemplateTagFunction')
def CallingTemplateTagFunction(price):
return price*10/100
我想在普通函数中调用GetValue函数。
例如:
正常的python函数:
def Test(request):
CallingTemplateTagFunction(50) # How to call django template tag function?
您可以在某处编写函数:
def MyUsefulFunction(price):
return price*10/100
然后在您的视图和模板标签中使用它:
from somewhere import MyUsefulFunction
# in templatetags:
@register.filter(name='CallingTemplateTagFunction')
def CallingTemplateTagFunction(price):
return MyUsefulFunction(price)
# in views:
def Test(request):
MyUsefulFunction(50)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句