django template {% url %}

64 views
Skip to first unread message

颜刚

unread,
Apr 3, 2016, 12:11:10 PM4/3/16
to Django users


i have this code in my template:

{% for action in actions %}
<li>
    <a href="{% url {{ action.name}} %}">{{ action.name_short }}</a>
</li>
{% endfor %}

but that's error:

Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '{{' from '{{'

i want to use var in {% url {{}} %},can i?
anyone can help me ?

Larry Martell

unread,
Apr 3, 2016, 12:16:43 PM4/3/16
to django...@googlegroups.com
You don't need {{ }} around action.name if you're referencing it
inside of a {% %} block

颜刚

unread,
Apr 4, 2016, 9:33:29 AM4/4/16
to Django users
yes,you are right,i have noticed that,but now i have a new error:

i have this code in my template:

{% for action in actions %}
<li>
    <a href="{% url action.url_alias %}">{{ action.name_short }}</a>
</li>
{% endfor %}

the value of action.url_alias is  'user-edit' i.id host 'account' ,that's what i want value from table,i use django-hosts in my project,the error is that:

Reverse for ''user-edit' i.id host 'account'' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

but when i use the value  'user-edit' i.id host 'account' directly in {%%} like this {% url  'user-edit' i.id host 'account' %},that's ok.
the i.id is one of another for loop's value.how can i do this,thanks for help.
Reply all
Reply to author
Forward
0 new messages