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.
精彩评论