开发者

Nested Tag inside URL tag in Django Template

开发者 https://www.devze.com 2023-03-20 18:29 出处:网络
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 l

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 cre开发者_C百科ated nested tag and the {{ item.name }} inside the view arg which doesn't work. Any ideas?


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

0

精彩评论

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