forms组件源码

"""
切入点
    form_obj.is_vaild()
"""

def is_valid(self):
        """
        Returns True if the form has no errors. Otherwise, False. If errors are
        being ignored, returns False.
        """
        return self.is_bound and not self.errors
        # 如果is_vaild要返回True的话 
        # 那么self.is_bound要为True
        # self.errors要为False
        
self.is_bound = data is not None or files is not None
# 只要你传值了 肯定为True


 @property
def errors(self):
        "Returns an ErrorDict for the data provided for the form"
        if self._errors is None:
            self.full_clean()
        return self._errors
    
# forms组件所有的功能都基本出自于该方法
def full_clean(self):
        self._clean_fields()  # 校验字段 + 局部钩子
        self._clean_form()  # 全局钩子
        self._post_clean()

 

图解

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2021-06-17 20:18  Palpitate~  阅读(53)  评论(0编辑  收藏  举报