开发者

Passing named arguments to functions in Django templates

I have in my Django controller a function that is called as follows:

trip.driverTrip.filter(status='pending')

What it will be the equivalent of calling this in a template. If I just want to call the filter function, the following will suffice:

{{trip.driverTri开发者_Go百科p.filter}}

But is there a way to pass it arguments ?


There are no controllers in Django ... Do you mean a view ;) ?

The equivalent in a template would be :

{{ trip.driverTrip|filter:"pending" }}

However, for this to work, your function filter has to be registered as a template filter, and 'loaded' in your template. You cannot just call any function (or method) like this. Plus, if you do this, assuming that the preceding conditions are fulfilled it means that you pass trip.driverTrip as the first argument to filter, and "pending" is an additional argument.

Does this answer your question ?


django template system, calling a function inside a model explains, you can't do it directly, but it that site also suggests a workaround.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜