mobile = self.data.get("mobile")
code = self.data.get("code")
r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=0, charset="utf8", decode_responses=True)
redis_code = r.get(str(mobile))
# 然后比较两个code值
if code != redis_code:
raise forms.ValidationError("验证码不正确")
# 如果正确直接返回
return code