Django_form补充
問題1:? 注冊(cè)頁面輸入為空,報(bào)錯(cuò):keyError:找不到password
def clean(self):
??????? print("---",self.cleaned_data)
??????? #? if self.cleaned_data["password"]==self.cleaned_data["repeat_password"]:?????? ?
??????? #? 報(bào)錯(cuò)原因:self.cleaned_data是干凈數(shù)據(jù),如果頁面沒有輸入內(nèi)容,則self.cleaned_data沒有password。
??????? 改如下:
??????? if self.cleaned_data.get("password")==self.cleaned_data.get("repeat_password"):
??????????? return self.cleaned_data
??????? else:
??????????? raise ValidationError("兩次密碼不一致")
?
?2? 為什么要用全局clean():
按子段順序一一校驗(yàn),即校驗(yàn)到username時(shí),你無法使用self.cleaned_data.get("password")。
而局部鉤子使用完,到全局時(shí),已經(jīng)可以使用所有的self.cleaned_data
3
?
分類:?Django系列學(xué)習(xí)轉(zhuǎn)載于:https://www.cnblogs.com/wangmo/p/8467220.html
總結(jié)
以上是生活随笔為你收集整理的Django_form补充的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 666A-Reberland Lingu
- 下一篇: CentOS 6.9下的Setup工具(