一、在后台,自定义formhtml
class PolicyForm(forms.Form):post
#==label 用来控制 form 字段的 中文显示,widget 能够控制其余属性,好比样式等ui
name = forms.CharField(label="名称*:", error_messages={'required': '名称不能为空'},max_length=20,widget=forms.TextInput())spa
send_pri = forms.ChoiceField(label='发送优先级:',choices=((u'H', u'高'), (u'N', u'中'),(u'L', u'低')),widget=forms.Select())orm
二、在html页面htm
<form id="policy_form" action="/policy_save" method="post"> get
<table class="form-table">input
<!--{{ form.as_ul }}--> # 这是第一种写法,在<ul> 显示表单it
<!-- {{ form.as_p }}--> # 这是第二种写法,在<p> 显示表单io
<!--{{ form.as_table }}--> # 这是第三种写法,在<table>显示表单
<!--{% for field in form %} # 这是第四种写法,以循环形式显示表单
<tr>
<th width='220'>{{ field.label_tag }}</th>
<td height='8'>{{ field }}<br><span class='helptxt'>{{ field.help_text }}</span></td>
<td class='errormsg' width='120'>{{ field.errors }}</td>
</tr>
{% endfor %}
-->
<tr> # 这是第五种写法,把全部字段所有列出
<th width='220'>
{{ form.name.label_tag }}
</th>
<td height='8'>
{{ form.name }}
{{ form.name.help_text }}
</td>
<td width='120'>
{{ form.name.errors }}
</td>
</tr>
。。。。。N个<tr></tr>,只要把要显示的字段所有列出来便可
</table>
<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="注册信息" /></p>
</form>