我有选择列表。我想一一获得HTML的价值
class ProfileForm(ModelForm):
class Meta:
model = UserInfor
fields = [ 'gender']
widgets = {
'gender': forms.RadioSelect(choices=GENDERS),
}
labels = {
'gender': "Gender",
}
def profile(request):
user_info = ProfileForm()
return render(request, 'pages/test.html', {'user_info': user_info)
{% for choice in genders %}
<label class="radio-inline" class="radio-inline"><input type="radio" value="???">{{ ??? }}</label>
{% endfor %}
答案 0 :(得分:0)
{% for g_value, g_label in user_info.fields.gender.choices %}
<label class="radio-inline" class="radio-inline"><input type="radio" value="{{ g_value }}">{{ g_label }}</label>
{% endfor %}