Align radio buttons horizontally in django forms

前端 未结 7 1776
借酒劲吻你
借酒劲吻你 2021-02-08 01:50

HI

I want to align the radio buttons horizontally. By default django forms displays in vertical format.

feature_type  = forms.TypedChoiceField(choices =         


        
7条回答
  •  执念已碎
    2021-02-08 02:36

    According to the Django docs 'attrs' is a dictionary containing HTML attributes to be set on the rendered widget.

    With that in mind a simple form based solution would be something like the following:

    feature_type  = forms.TypedChoiceField(
        choices = formfields.FeatureType,
        widget = forms.RadioSelect(attrs={
            'style': 'display: inline-block'
        })
    )
    

提交回复
热议问题