标签:containe tin label hold rom code htm horizon BMI
以text input框为例
模板文件需要有bootstrape
from django import forms class DepForm(forms.Form): name = forms.CharField(label="部门名称",widget=forms.TextInput(attrs={‘class‘:‘form-control‘})) #可以添加多个 count = forms.IntegerField(label="部门人数") #IntegerField没有这个属性 def department_add(request): form_obj = DepForm() return render(request,‘department_add.html‘,{‘form_obj‘:form_obj})
模板文件如下:
{% extends ‘layout.html‘ %}
{% block content %}
<div class="container">
<div style="margin-top: 20px">
<form class="form-horizontal">
<div class="form-group">
<label for="{{ form_obj.name.id_for_label }}" class="col-sm-2 control-label">{{ form_obj.name.label }}</label>
<div class="col-sm-8">
{# <input type="email" class="form-control" id="inputEmail3" placeholder="Email">#}
{{ form_obj.name }}
{{ form_obj.name.errors }}
</div>
</div>
<div class="form-group">
<label for="{{ form_obj.count.id_for_label }}" class="col-sm-2 control-label">{{ form_obj.count.label }}</label>
<div class="col-sm-8">
{{ form_obj.count }}
{{ form_obj.count.errors }}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
</div>
</div>
{% endblock %}
标签:containe tin label hold rom code htm horizon BMI
原文地址:https://www.cnblogs.com/guniang/p/11382077.html