[英]Django form-fields: Styling for Bootstrap without losing functionality?
So form.as_p
in django gives a plain, yet very catered form, with field inputs matching the entity attribute type, like so: 因此,django中的
form.as_p
给出了一种简单而又非常适合的形式,其字段输入与实体属性类型匹配,如下所示:
Notice how vintage
is a dropdown item, and so is brand
. 注意
vintage
是一个下拉项, brand
。 But then again, it's very plain . 但是话又说回来,这很简单 。
I want to use bootstrap styling with the django form without losing the way django customizes each input type by the model attributes. 我想将引导样式与django表单一起使用,而又不会失去django通过模型属性自定义每种输入类型的方式。
I have managed to achieve this: 我设法做到这一点:
By doing this in my .pug
template: 通过在我的
.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")
But how can I both get the style, and the catered form inputs from django? 但是我如何才能同时从django中获取样式和可满足要求的表单输入呢? In my current form all fields are simple input types.
在我当前的形式中,所有字段都是简单的输入类型。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.