简体   繁体   中英

Calling function with variable from view template, django

in template

{{object.get_resource}}

in views.py(DetailView)

def get_resource(self):
    return "my resource"

It works.

Now, I want to pass the variable to object.

Is it possible to do like this below?

{{object.get_resource(1)}}

def get_resource(self,num):
    return "my resource:{0}".format(num)

Sadly, you cannot pass arguments to functions in Django templates.

You ought to write your own template tags.

Use this answer as reference:-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM