如何在django模板中使用变量(true或false)进行连接检查
<select id="company_id" name="company_id" class="form-control " >
<option value="">Select Company {{company_id}}</option>
{% for row in brands %}
{% if row.id == company_id %}
<option value="{{ row.id }}" >{{ row.title }} </option>
{% else %}
<option value="{{ row.id }}" selected>{{ row.title }} </option>
{% endif %}
{% endfor %}
</select>
让我们假设你有一个模型,在其他字段中你有一个布尔字段true,你想检查布尔字段是真还是假,如果真通过这个标题,如果假通过这个标题,那么你必须像这样做
模型class User(models.Model):
first_name = models.CharField(max_length=50, blank=True)
last_name = models.CharField(max_length=75, blank=True)
email_confirmed = models.BooleanField(default=False)
当你在模板
中获取modeldata时{% for user in users %}
{{user.first_name}}
{{user.last_name}}
{% if user.email_confirmed == True %}}
<h1>Authentic User</h1>
{% else %}
<h1>Not a authentic user</h1>
{% endif %}
{% endfor %}
我希望现在你能明白我想解释的意思