如何在django-crispy-forms中的两列布局上散布表单字段? [英] How to spread form fields on two column layout in django-crispy-forms?

查看:55
本文介绍了如何在django-crispy-forms中的两列布局上散布表单字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了一些建议,建议使用django-crispy-forms在Django中创建表单.

I have received a few recommendation to use django-crispy-forms for creating forms in Django.

我一直在寻找文档几个小时,却找不到解决方法,将表单字段分布在两列上.

I have been looking for a couple of hours into the documentation and can't figure out a way how to spread the form fields over two columns.

请看此示例此处

        helper = FormHelper()
        helper.form_class = 'form-horizontal'
        helper.layout = Layout(
            Field('text_input', css_class='input-xlarge'),
            Field('textarea', rows="3", css_class='input-xlarge'),
            'radio_buttons',
            ...
        )

我可以看到如何设置出现的顺序.但是布局仍然与普通的 {{form.as_p}} 没什么不同.我希望我在这里丢失了一些东西,否则使用此附加组件几乎没有用?

I can see how the sequence of appearance can be setup. But the layout is still no different then a plain {{ form.as_p }}. I hope I am missing here something otherwise there is little use in using this add-on?

推荐答案

请确保您已包含引导css文件,该应用程序已添加到 INSTALLED_APPS .

Make sure you have bootstrap css files included, the application added to INSTALLED_APPS.

然后,您必须在模板中包含进行 {%load crispy_forms_tags%} 的django-crispy-forms标签,最后像在例子.您所链接的示例中显示的所有内容.这应该产生一个水平形式.

Then you have to include django-crispy-forms tags doing {% load crispy_forms_tags %} in your template and finally do {% crispy form %} as in the example. All that is shown in the example you linked. This should produce a horizontal form.

这与 as_p 几乎没有什么不同,这是可自定义的布局,无需编写模板,这很容易出错.这些幻灯片可能会对您有所帮助.

Nothing close to as_p, this is a customizable layout, no need to write templates, which is very error prone. These slides might help you.

这篇关于如何在django-crispy-forms中的两列布局上散布表单字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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