django中bootstrap3样式水平窗体的模板
django-bootstrap-form-horizontal的Python项目详细描述
这是一组表单模板,用于实现 Django表格。处理所有默认字段类型,包括 Pikaday日期时间字段的包装。
安装:
pip install django-bootstrap-form-horizontal
添加到INSTALLED_APPS:
INSTALLED_APPS = ( ... "bootstrap_form_horizontal", ... )
用法:
{% include "bootstrap_form_horizontal.html" with form=myform %}
模板接受以下上下文:
- ^{tt2}$: The form to render.
- ^{tt3}$: The text for a submit button with class ^{tt4}$. If not specified, no submit button is rendered.
- ^{tt5}$: If not 0, will wrap form with ^{tt6}$. Default: ^{tt7}$ If you specify ^{tt8}$, the form will be rendered without wrapping, and you must provide your own ^{tt9}$ wrapper.
- ^{tt10}$: The grid class(es) to use on label elements. Default: ^{tt11}$.
- ^{tt12}$: The grid class(es) to use on field elements. Default: ^{tt13}$.
要正确渲染,必须包含各种css/js。为了方便,贩卖 bootstrap包含在这里-尽管您可能已经在加载它了 如果您对此应用程序感兴趣,请选择您的项目:
<!-- Bootstrap --> <link rel='stylesheet' type='text/css' href='{{ STATIC_URL }}bootstrap_form_horizontal/vendor/bootstrap/css/bootstrap.css' /> <script type='text/javascript' src='{{ STATIC_URL }}bootstrap_form_horizontal/vendor/bootstrap/js/bootstrap.min.js'></script> <!-- Pikaday --> <link rel='stylesheet' type='text/css' href='{{ STATIC_URL }}bootstrap_form_horizontal/vendor/pikaday/css/pikaday.css' /> <script type='text/javascript' src='{{ STATIC_URL }}bootstrap_form_horizontal/vendor/pikaday/pikaday.js'></script> <script type='text/javascript' src='{{ STATIC_URL }}bootstrap_form_horizontal/datewidgets.js'></script>
示例
用表格包装,并包括提交按钮:
{% include "bootstrap_form_horizontal.html" with form=myform submit="Send it in" %}
自行包装表格:
<form method='post' class='form-horizontal' action='something'>{% csrf_token %} {% include "bootstrap_form_horizontal.html" with form=myform wrap=0 %} <input type='submit' value='Go!' /> </form>
更改响应列类:
{% include "bootstrap_form_horizontal.html" with label_class='col-sm-2 col-xs-4' field_class='col-xs-10 col-sm-8' %}
- 滚动自己的表单模板?
- _bootstrap_form_horizontal_field.html:呈现单个标签/字段对需要field作为上下文;也接受label_class和field_class如上所述。
- _bootstrap_form_horizontal_non_field_errors.html:显示封装在引导错误类中的非字段错误。需要form作为上下文;接受label_class和field_class。