How to call django template tags from a normal function?
For instance:
Django template tag:
@register.filter(name='CallingTemplateTagFunction')
def CallingTemplateTagFunction(price):
return price*10/100
I wanna to call GetValue function in a normal function.
For instance:
Normal python function:
def Test(request):
CallingTemplateTagFunction(50) # How to call django template tag function?
You can write somewhere your function:
def my_useful_function(price):
return price * 10 / 100
And then use it in your views and in template tags:
from somewhere import my_useful_function
# in templatetags:
@register.filter(name='calling_template_tag_function')
def calling_template_tag_function(price):
return my_useful_function(price)
And then in views:
def test(request):
my_useful_function(50)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With