FORM组件
form组件 忽略的 一个问题: 没有对用户输入的值进行校验 1:前台和后台都要校验 2:减少后台数据库的压力 views.py: from django.forms import Form from django.forms import fields class LoginForm(Form): #验证的规则 username=fields.CharField( required=True, max_length=18, min_length=6, error_message={ "required":'不能为空', "max_length":'太长了', "min_length":"太短了", }) pwd =fields.CharField() def login(request): if request.method=='GEt': return render(request,'login.html') else: obj =LoginForm(request.POST) print(obj) if obj.is_valid(): print(obj.cleaned_data)##对象 else: print(obj.errors)## 对象__str__ return render(request,'login.html',{'obj':obj}) html: