用单选按钮渲染ChoiceField [英] Render ChoiceField with radio buttons

查看:67
本文介绍了用单选按钮渲染ChoiceField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从模型中构建了此表单。

I've constructed this form from a model.

class Configure_template(forms.Form):
    subject_type = forms.ChoiceField(choices=Subject_type.objects.all())

我想渲染这个使用单选按钮,但html中的for却有问题,

And I want to render this using radio buttons but I have problems with the for in the html,

感谢任何建议。

推荐答案

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

Use a RadioSelect widget on your form field:

subject_type = forms.ChoiceField(choices=Subject_type.objects.all(),
    widget=forms.RadioSelect)

这篇关于用单选按钮渲染ChoiceField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆