zoukankan      html  css  js  c++  java
  • Django_Form表单补充

    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

  • 相关阅读:
    Linux Bash管理
    Linux文件查看
    Linux文件目录
    yum Linux软件安装工具
    第十六、十七天,关于面向对象
    第十四天,内置函数
    第十二天
    第十一天
    第十天
    第九天(开始函数)
  • 原文地址:https://www.cnblogs.com/hedeyong/p/7488018.html
Copyright © 2011-2022 走看看