我有一个 ChoiceField,现在如何在需要时获取“标签”?

class ContactForm(forms.Form):
     reason = forms.ChoiceField(choices=[("feature", "A feature"),
                                         ("order", "An order")],
                                widget=forms.RadioSelect)
form.cleaned_data["reason"] 只会给我“功能”或“订单”左右。

最佳答案

这可能有帮助:

reason = form.cleaned_data['reason']
reason = dict(form.fields['reason'].choices)[reason]

关于python - 如何在 Django 表单 ChoiceField 中获取选择的标签?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/761698/

10-13 02:07