普通标签
from django import forms
class form_view(forms.Form):
name = forms.CharField(
required=True, # 输入不能为空
label="姓名:", # 页面上的input框名字
initial="张三", # 框里的默认值
help_text="输入姓名", # 输入框后的帮助文本
min_length=6, # 最小长度为6
error_messages={"min_length":"长度最少6位","required":"输入值不能为空!"}, # 错误提示信息
widget=forms.widgets.TextInput() # 输入框为普通文本
)
秘文标签
password = forms.CharField(
label="密码:",
min_length=8,
max_length=10,
error_messages={"min_length": "长度最少8位","max_length":"长度最多10位" ,"required": "输入值不能为空!"},
widget=forms.widgets.PasswordInput() # 秘文输入
)
单选标签
sex = forms.ChoiceField(
label="性别:",
initial=1, # 默认选择
choices=((1,'男'),(2,'女')),
widget=forms.widgets.RadioSelect()
)
单选下拉框
city = forms.ChoiceField(
label="城市:",
initial=1,
choices=((1,'北京'),(2,'上海')),
widget=forms.widgets.Select()
)
多选
happy = forms.MultipleChoiceField(
label="爱好:",
choices=((1,'打游戏'),(2,'听音乐'),(3,'看书'),(4,'跑步')),
widget=forms.widgets.CheckboxSelectMultiple,
)
多选下拉框
school = forms.MultipleChoiceField(
label="意向学校:",
choices=((1,"北京大学"),(2,"清华大学"),(3,"复旦大学"),(4,"人民大学"),(5,"民族大学")),
widget=forms.widgets.SelectMultiple,
)
单选
status = forms.ChoiceField(
label="是否记住我!",
choices=((True,"是"),(False,"否")),
widget=forms.widgets.CheckboxInput,
)
时间
date = forms.CharField(
label="时间",
widget=forms.widgets.TextInput(attrs={"type":"date"}) # 给标签加属性
)