clean_data的值调用了clean之后才有的
来源:9-13 手机验证码动态登录 - 2
Demin
2020-02-27
在视频1:43秒,老师你说cleaned_data的值,是调用clean之后才放到clean_data里面的。所有我有一个问题,在重写clean的时候,调用了cleaned_data的值,是不是与老师说的"调用clean之后才放到里面"有出路呢?
def clean(self):
mobile = self.cleaned_data["mobile"]
code = self.cleaned_data["code"]
r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=0, charset="utf8", decode_responses=True)
redis_code = r.get(str(mobile))
if code != redis_code:
raise forms.ValidationError("验证码不正确")
return self.cleaned_data
写回答
1回答
-
Demin
提问者
2020-02-27
def clean(self): """ Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named '__all__'. """ return self.cleaned_data
看了源代码,clean()是返回了clean_data的值;clean在field.clean()之后才被调用
012020-02-29
相似问题