在raise 和 form.add_error 抛出异常的情况中 两种都实用
raise 抛出异常在钩子函数中
点击查看代码
def clean_domain_ssl_key_content(self):
"""根据协议判断 内容"""
###判断协议httphttps
backend_schema = str(self.cleaned_data.get('backend_schema', None)).strip()
# domain_ssl_cert_content = self.cleaned_data.get('domain_ssl_cert_content', None)
# domain_ssl_key_content = self.cleaned_data.get('domain_ssl_key_content', None)
domain_ssl_cert_content = str(self.cleaned_data.get('domain_ssl_cert_content', None))
domain_ssl_key_content = str(self.cleaned_data.get('domain_ssl_key_content', None))
if backend_schema == '1':
if (not domain_ssl_cert_content) and (not domain_ssl_key_content):
return domain_ssl_key_content
# self.add_error('domain_ssl_key_content','您现在添加的是http协议 cert 和key 必须同时为空err')
raise ValidationError('错误: 您现在添加的是http协议 cert 和key 必须同时为空')
###https协议
if domain_ssl_cert_content and domain_ssl_key_content:
###存在都
return domain_ssl_key_content


form.add_error 抛出异常
点击查看代码
def clean_domain_ssl_key_content(self):
"""根据协议判断 内容"""
###判断协议httphttps
backend_schema = str(self.cleaned_data.get('backend_schema', None)).strip()
# domain_ssl_cert_content = self.cleaned_data.get('domain_ssl_cert_content', None)
# domain_ssl_key_content = self.cleaned_data.get('domain_ssl_key_content', None)
domain_ssl_cert_content = str(self.cleaned_data.get('domain_ssl_cert_content', None))
domain_ssl_key_content = str(self.cleaned_data.get('domain_ssl_key_content', None))
if backend_schema == '1':
if (not domain_ssl_cert_content) and (not domain_ssl_key_content):
return domain_ssl_key_content
self.add_error('domain_ssl_key_content','您现在添加的是http协议 cert 和key 必须同时为空err')
# raise ValidationError('错误: 您现在添加的是http协议 cert 和key 必须同时为空')
###https协议
if domain_ssl_cert_content and domain_ssl_key_content:
###存在都
return domain_ssl_key_content
##raise ValidationError('您现在添加的是https协议 cert和key 必须同时有内容')
self.add_error('backend_schema', '您现在添加的是https协议 cert和key 必须同时有内容err')
# raise ValidationError('raise您现在添加的是https协议 cert和key 必须同时有内容')

浙公网安备 33010602011771号