我不久前一直在使用 django-crispy-forms 并我想知道是否有一种方法可以设置输入的位置,例如col-md-XX
类或其他东西,使其看起来更好,而不仅仅是字段列表。
这是一个例子:
This is a "normal" render of a crispy-form using {{ form | crispy }}
or {% crispy form %}
I want to be rendered like this with python code in the forms.py or something like that. Actually I make this by typing HTML code and rendering with as_crispy_field
tag.
最后当我渲染表单时{% crispy form %}
我可以使用内联样式的单选按钮,但是使用as_crispy_field
标签,收音机看起来仍然是垂直的,即使InlineRadios
助手中的布局。
With as_crispy_field
With {% crispy form %}
有没有办法让收音机看起来水平或与as_crispy_field
tag?
你可以使用脆InlineRadio布局 — django-crispy-forms 1.0.0 文档 https://django-crispy-forms.readthedocs.io/en/latest/layouts.html?highlight=inlineradio#bootstrap-layout-objects
class ProgramaForm(forms.ModelForm):
class Meta:
model = MyModel
fields = ['programa']
def __init__(self, *args, **kwargs):
super(ProgramaForm, self).__init__(*args, **kwargs)
self.fields['programa'].required = True
self.helper = FormHelper()
self.helper.layout = Layout(
Div(InlineRadios('programa')),
)
self.helper.add_input(Submit('submit', 'Submit'))
使用 Django 的 Crispy Forms 实现布尔值的水平单选按钮 https://gist.github.com/linxuedong/e559b437a0b7d4dd6f6cd8a6d1a26e77
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)