0
장고 템플릿 내 선택 상자에서 값을 선택하지 않았습니다. 다음 코드가 있습니다.django 템플릿 <select> 상자가 값을 선택하지 않습니다
template_name.html
<select name="class_id" >
{% for object in classes %}
<option value="{{ object.id }}"
{% if object.id == class_id %} selected="selected" {% endif %}>
{{ object.name }}
</option>
{% endfor %}
</select>
view.py
class_id = request.POST.get('class_id', 0)
context_data = {'class_id':class_id}
return render(request, "template_name.html",context_data)
우리가 내가 다음과 같은 출력을 얻을
{% for object in classes %}
{{ object.id }} = {{ class_id }} <br>
{% endfor %}
다음 템플릿에이 코드를 실행하기 때문에이 문제가 이상하다
1 = 3
2 = 3
3 = 3
고맙습니다. –