【发布时间】:2020-01-19 03:42:02
【问题描述】:
我正在尝试使用内置验证器设置我在 Django 中忘记的密码,但如果重现错误我没有得到任何响应,但它应该显示其他类的错误,我该如何解决这个问题?
forms.py
class RestorePasswordForm(SetPasswordForm):
new_password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'Password','required': True}))
new_password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'Password','required': True}))
观看次数
def post(self, request,token):
form = RestorePasswordForm(request.POST)
if form.is_valid():
obj = token(token)
if obj:
this_user = User.objects.get(id=obj.email_id)
if not this_user:
return False
this_user.set_password(request.POST.get('new_password2'))
this_user.save()
obj.token = None
obj.save()
return JsonResponse({"message":form.errors})
浏览器响应显示
{"message": {}}
【问题讨论】:
标签: django django-forms