Ardavan
Ardavan

Reputation: 1936

Nested Tag inside URL tag in Django Template

I have a list of items in my template which produce a table of hrefs. Now I want to send back the item.name to the appropirate view function based on the clicked item. The code should look something like this:

{% for item in myList %}
    <li><a href="{% url myView arg="{{ item.name }}"%}"> {{ item.name }} </a> <li>
{% endfor %}

And the problem is the created nested tag and the {{ item.name }} inside the view arg which doesn't work. Any ideas?

Upvotes: 0

Views: 1515

Answers (1)

Bernhard Vallant
Bernhard Vallant

Reputation: 50806

{% url myView item.name %} should work, if the url pattern expects a positional argument! See the documentation of the url template tag!

Upvotes: 1

Related Questions