Skip to content Skip to sidebar Skip to footer

Django Template, Send Two Arguments To Template Tag?

Can anyone tell me if its possible to send multiple variables from field names to a template tag? this question How do I add multiple arguments to my custom template filter in a dj

Solution 1:

From my point of view it looks easier to use a simple tag instead of a template filter so you can call it without needing to send a string.

https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#simple-tags

Your template would be just:

{% load remaining_cost %}
{# Don't forget to load the template tag as above #}

<th>{% remaining_cost item.cost_per_month item.install_date item.comtract_length %}</th>

and the template tag would be:

@register.simple_tag
def remaining_cost(cost_per_month, install_date, contract_length):
    cost =contract_remainder(install_date, contract_length) * cost_per_month
    return cost 

Post a Comment for "Django Template, Send Two Arguments To Template Tag?"