手机验证码传入表单从cleaned_data取出为None
来源:9-12 手机验证码动态登录 - 1
ahomm
2020-12-02
class DynamicLoginPostForm(forms.Form):
mobile = forms.CharField(required=True, min_length=11, max_length=11)
sms_code = forms.CharField(required=True, min_length=4, max_length=4)
def clean(self):
# mobile = self.data.get("mobile")
# sms_code = self.data.get("sms_code")
mobile = self.cleaned_data["mobile"]
sms_code = self.cleaned_data["sms_code"]
print(sms_code)
r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=0, charset='utf8', decode_responses=True)
redis_code = r.get(str(mobile))
if redis_code != sms_code:
raise forms.ValidationError("验证码不正确")
else:
return self.cleaned_data
[02/Dec/2020 23:08:19] “POST /send_sms/ HTTP/1.1” 200 21
None
[02/Dec/2020 23:08:39] “POST /d_login/ HTTP/1.1” 200 6660
C:\Users\zhq_9\PycharmProjects\TTBOnline\apps\users\forms.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks…
写回答
2回答
-
ahomm
提问者
2020-12-03
已经解决,是当前表单验证的验证码变量sms_code 与前端name属性的code不一,无法从动态登录表单中取到验证码导致的
00 -
bobby
2020-12-03
你这里的form表单的完整代码贴一下我看看
022020-12-04
相似问题