Django:在模板中选择带有默认字段的选项

Django:在模板中选择带有默认字段的选项,django,twitter-bootstrap,django-templates,Django,Twitter Bootstrap,Django Templates,我想尝试在选择选项表单中选择我的默认字段。我在这里的主要表单是表单和表单。状态获取所有用户可能状态和用户表单。初始状态获取用户当前状态: <div class="col-lg-9 select mb-3"> <select name="status" ng-model='discussionsSelect' class="custom-select form-control"> {% fo

我想尝试在选择选项表单中选择我的默认字段。我在这里的主要表单是
表单
表单。状态
获取所有用户可能状态和
用户表单。初始状态
获取用户当前状态:

<div class="col-lg-9 select mb-3">
    <select name="status" ng-model='discussionsSelect' class="custom-select form-control">
        {% for status in form.status %}
            <option value="{{user_form.initial.status}}" 
                {% if status == user_form.initial.status %}selected="selected"{% endif %}>
                {{status}}
            </option>
        {% endfor %}
    </select>
</div>

{%的状态为form.status%}
{{status}}
{%endfor%}
但它并没有被选为默认值


您可以这样做:

<select ... name="status">
{% for value, label in form.fields.status.choices %}
    <option value="{{ value }}"{% if user_form.status.value == value %} selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>

{%为值,标签为form.fields.status.choices%}
{{label}}
{%endfor%}

谢谢你似乎是真的,但在我的例子中,当我在
中放入
for loop
时,它不会打印输出。但是在
之外,一切都是真的您的
用户表单.状态.值是什么?分享你现在使用的代码。我知道答案了。我应该这样做:
{%if account.status==value%}
。非常感谢你