Align radio buttons horizontally in django forms

前端 未结 7 1773
借酒劲吻你
借酒劲吻你 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:50

    I've come up with an alternative solution. If you are using bootstrap to render your forms, you can add the .form-check-inline class to the input and the field will display horizontally. Listed below is code that shows what I'm describing. I hope this helps someone from reinventing the wheel. Thanks for reading. Take care and have a good day.

                    feature_type = forms.MultipleChoiceField(
                    required=False,
                    ...
                    widget=forms.CheckboxSelectMultiple(attrs={'class': 'form-check-inline'})
                    )
    

提交回复
热议问题