我这样定义我的form
class BackForm(forms.Form): email = forms.CharField(widget=forms.EmailInput(attrs={'class':'form-control','placeholder':"请输入邮箱账号/手机号",'required':'email不能为空'})) password = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':"请输入密码",'required':'password不能为空'}))
当我在只需要用到email的时候,我在html页面只获取email相关信息
<form action="{% url 'send_mail' %}" method="post"> {% csrf_token %} <ul> <li class="form-group has-error">{{ backform.email }}</li> </ul> <div> <input type="submit" class="btn btn-micv5 btn-block">提交</input> </div> <div class="tips-error bg-danger">错误提示</div> </form>
但在验证的时候出错了
def send_mail(request): try: if request.method =='POST': backform = BackForm(request.POST) if backform.is_valid():
is_valid()返回的为false
我判断应该是密码没填写,不过这里只需要使用邮箱,
不知道是不是这个错误,求助大神!!!
'required':'password不能为空'
这段去掉