view.py
class LoginForm(forms.Form): name=forms.CharField(label="用户名",widget=forms.TextInput(attrs={"class":"form-controls"})) pwd=forms.CharField(label="密码",widget=forms.PasswordInput(attrs={"class":"form-controls"})) def login(request): form =LoginForm() return render(request,"login.html",{"form":form})
html
<div> <form action=""> <div class="form-froup"> {{ form.name }} </div> <div class="form-froup"> {{ form.pwd }} {# 加错误信息#} {{ form.pwd.errors.0 }} </div> </form> </div>