HI
欲水平对齐的单选按钮。默认情况下Django的形式显示在垂直格式。
I want to align the radio buttons horizontally. By default django forms displays in vertical format.
feature_type = forms.TypedChoiceField(choices = formfields.FeatureType, widget = forms.RadioSelect)
有没有办法,我们可以通过单选按钮对齐的任何特殊参数?
Is there any special parameter that we can pass for radio buttons alignment?
在此先感谢
多数民众赞成在 RadioField
的行为。如果你想要呈现的水平,创建水平的渲染器,喜欢的东西如下:
Thats the behavior of the RadioField
. If you want it rendered horizontally, create a horizontal renderer, like something as follows:
from django.utils.safestring import mark_safe
class HorizontalRadioRenderer(forms.RadioSelect.renderer):
def render(self):
return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))
class ApprovalForm(forms.Form):
approval = forms.ChoiceField(choices=APPROVAL_CHOICES,
initial=0,
widget=forms.RadioSelect(renderer=HorizontalRadioRenderer),
)
上一篇:什么是用于alignas和alignof关键字?关键字、alignas、alignof
下一篇:WPF工具栏项目HorizontalAligment ="右"工具栏、项目、WPF、QUOT