使用单选按钮渲染ChoiceField

Ant*_*zón 3 django django-forms

我从模型中构建了这个表单.

class Configure_template(forms.Form):
    subject_type = forms.ChoiceField(choices=Subject_type.objects.all())
Run Code Online (Sandbox Code Playgroud)

我想用单选按钮渲染这个但是我在html中遇到问题,

谢谢你的任何建议.

Tim*_*ony 6

在表单字段上使用RadioSelect小部件:

subject_type = forms.ChoiceField(choices=Subject_type.objects.all(),
    widget=forms.RadioSelect)
Run Code Online (Sandbox Code Playgroud)