我有一个ChoiceField,现在如何在需要时获取“标签”?
class ContactForm(forms.Form): reason = forms.ChoiceField(choices=[("feature", "A feature"), ("order", "An order")], widget=forms.RadioSelect)
form.cleaned_data["reason"] 只会给我“功能”或“命令”左右。
form.cleaned_data["reason"]
这可能会有所帮助:
reason = form.cleaned_data['reason'] reason = dict(form.fields['reason'].choices)[reason]