58๐
You can create a simple template tag to call any method with any arguments:
from django import template
register = template.Library()
@register.simple_tag
def call_method(obj, method_name, *args):
method = getattr(obj, method_name)
return method(*args)
And then in your template:
{% call_method obj_customer 'get_something' obj_business %}
But, of course, crating of a specialized template tag is more safe ๐
@register.simple_tag
def get_something(customer, business):
return customer.get_something(business)
Template:
{% get_something obj_customer obj_business %}
๐คcatavaran
4๐
You cannot pass arguments to functions in Django templates.
Instead you can write your own template tag.
Here are some examples:
https://github.com/miohtama/LibertyMusicStore/blob/master/tatianastore/templatetags/content.py
๐คMikko Ohtamaa
- [Django]-How to use "AND" in a Django filter?
- [Django]-Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually
- [Django]-Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed. (Django 1.8 and OSX ElCapitan)
Source:stackexchange.com