Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass {% url %} to custom template tag in Django

I'm developing a custom Django template tag that requires multiple arguments. One of those arguments is a URL. When I try to do this:

{% my_tag arg1 {% url "myview" %} arg3=5 %}

I get the following template syntax error: Could not parse the remainder: '{%' from '{%'

How can I pass a URL to a custom template?

like image 612
zmbq Avatar asked Dec 04 '25 10:12

zmbq


1 Answers

Simple url tag supports assignment.

{% url 'myview' as my_url %}
{% my_tag arg1 my_url arg3=5 %}
like image 175
Bogdan Iulian Bursuc Avatar answered Dec 06 '25 17:12

Bogdan Iulian Bursuc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!