python - Django 表单字段 : Styling for Bootstrap without losing functionality?

标签 python django twitter-bootstrap-3 django-forms

因此,django 中的 form.as_p 提供了一个简单但非常迎合需求的表单,其中字段输入与实体属性类型匹配,如下所示:

enter image description here

请注意,vintage 是一个下拉菜单项,brand 也是一个下拉菜单项。但话又说回来,这非常简单

我想在 django 表单中使用引导样式,而不会丢失 django 通过模型属性自定义每个输入类型的方式。

我已经成功实现了这一目标:

enter image description here

通过在我的 .pug 模板中执行此操作:

                form(method="post" action=".")
                    | {% csrf_token %}
                    for field in da_form
                        div(class="form-group row")
                            label(class="col-lg-4 col-md-3 cold-sm-6 col-form-label") {{field.label_tag}}
                            div(class="col-lg-8 col-md-3 cold-sm-6")
                                input(class="form-control") {{field}}
                    input(class="form-control")(type="submit" value="submit")

但是我如何两者从 django 获取样式和迎合的表单输入?在我当前的表单中,所有字段都是简单输入类型。

最佳答案

<form action="" method="POST">
{% for fields in form.visible_fields %}
<div label={{ fields.label_tag }} class="bootstrap class" id="your need">
<div class="your need">{{ fields }} </div>
{% endfor %}
<input type="submit" value="Submit">
</div>
</form>

关于python - Django 表单字段 : Styling for Bootstrap without losing functionality?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44083486/

相关文章:

java - 有没有办法使用 Lenskit 作为推荐引擎并从 Django/Python 调用他?

Python 双端队列 : difference from list?

python : Convert list of tuple to dict

python - 如何避免重复创建对象

css - 划分表格的行

javascript - 无法从 bootStrap 日期选择器读取值

python - 圆形阵列上的滚动窗口

django nginx Gunicorn,, 启动 : Job failed to start

python - 使用具有现有数据库 ID 字段的 Django 问题

css - 如果 bootstrap 3 grid 的宽度为 1500px,应该设置什么断点?