[Answered ]-How i can to pass parameter to model method in django template?

1👍

You can use a custom tag for that case. Check this
. I also had to build it for my project as I had to send arguments from template to my model’s method.
I created a folder in my app called templatetags and inside that folder was my __init__.py and myTags.py:

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)

then in template first I import my tags then I use my custom tag:

{% load myTags %}


{% call_method model 'method' argument1 argument2 argument3... %}

Leave a comment