Hi all not sure how to explain this clearly but here goes....
I need to开发者_开发问答 use two variables like so:
{% for client in clients %}
{% if user.client.username %}
I need {% if user.username %} but the value of username is in client.username from the loop.
is there a way to do this?
If I understand correctly, user
is a dict, and you want to lookup the value indexed by client
in each iteration of the loop - eg, user[client].username
in Python.
This (deliberately) isn't possible in Django templates - the language is limited, to force you to do pre-processing in code.
Instead, you should zip your two lists/dicts together before passing them to the template.
Are you trying to do something if the value of client.username
is equal to the value of user.client.username
? If so, you want:
{% if client.username == user.client.username %} # Works in Django 1.2 and above
{% ifequal client.username user.client.username %} # Works everywhere
精彩评论