:ジャンゴ 'ifと' 私は私のDjangoのhtmlページで次の操作を実行するテンプレート
{% if myList|length and ifequal myValue 'somestring' %}
blah blah
{% endif %}
が、私はエラーを取得: は、未使用の 'myValue' 式
場合の終わりにテンプレートでIf ANDを実行するにはどうすればよいですか?
:ジャンゴ 'ifと' 私は私のDjangoのhtmlページで次の操作を実行するテンプレート
{% if myList|length and ifequal myValue 'somestring' %}
blah blah
{% endif %}
が、私はエラーを取得: は、未使用の 'myValue' 式
場合の終わりにテンプレートでIf ANDを実行するにはどうすればよいですか?
私は二つの文でif
とifequal
を分離する必要があるかもしれないと思う:
{% if myList|length and myValue == 'somestring' %}
blah blah
{% endif %}
:
{% if myList|length and myValue == 'somestring' %}
blah blah
{% endif %}
はこのようなものであるべきboolean-operatorsの使用については、djangoのマニュアルを参照してください。 djangoテンプレートのcomplex-expressions
はこれを試してみてください:
{% if myList|length %}
{% ifequal myValue 'somestring' %}
blah blah
{% endifequal %}
{% endif %}
Django docs on boolean operators
Should be something like this
- view.py
def posts_request(request):
message=ApplyPost.objects.filter(blah blah)
if message:
return render (request,'blah.html',{'message':message})
- blah.html
{% if message %}
{% for post in message %}
{% if post.provider %}
....
{% endif %}
{% if post.accept == True and post.provider %}
...
...
{% endif %}
....You can add multiple if,elif, with Operators ....
{% endfor %}
{% if message %}
and
{% if a == b or c == d and e %}
それと比べて優先度の高い順位を持っているか、および括弧が不可能であることに注意してください。必要に応じてネストされたブロックを使用する
あなたと同じです。私はパーティーに遅刻していると思う。 – arulmr
@arulmr 2分遅れだが1票先に:) – kmerenkov
ごめんなさい。その偶然の一致。 – arulmr