zoukankan      html  css  js  c++  java
  • Django_form补充

    问题1:  注册页面输入为空,报错:keyError:找不到password

    def clean(self):

            print("---",self.cleaned_data)
            #  if self.cleaned_data["password"]==self.cleaned_data["repeat_password"]:        
            #  报错原因:self.cleaned_data是干净数据,如果页面没有输入内容,则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():

    按子段顺序一一校验,即校验到username时,你无法使用self.cleaned_data.get("password")。

    而局部钩子使用完,到全局时,已经可以使用所有的self.cleaned_data

    3

     
  • 相关阅读:
    Git的使用
    Flask(五)
    Flask(四)
    Flask(二)
    Flask(一)
    SDL 五子棋游戏
    c++单例模式
    ubuntu安装虚拟机
    git 命令
    汇编x86入门
  • 原文地址:https://www.cnblogs.com/wangmo/p/8467220.html
Copyright © 2011-2022 走看看