开发者

Django templates condition check

开发者 https://www.devze.com 2022-12-18 14:47 出处:网络
All, Can t we 开发者_StackOverflowdo the following in templates {% if subject.id == selected_id %} and also cannot we assign variable like {{selected=\"selected\"}}

All,

Can t we 开发者_StackOverflowdo the following in templates

{% if subject.id == selected_id %}

and also cannot we assign variable like {{selected="selected"}}

Thank........


This comparison will work in Django 1.2. For 1.1 you have to use ifequal:

{% ifequal subject.id  selected_id %}

For variable assignment you can use with.

{% with selected as 'selected' %}

{% endwith %}

Don't hesitate to read the documentation, it doesn't hurt.


Not as shown. Use the ifequal and with template tags instead.

0

精彩评论

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