'NoneType' 和 'NoneType' 重叠检查实例之间不支持“>”
'>' not supported between instances of 'NoneType' and 'NoneType' Overlapping Check
您好,我在验证检查中遇到了这个错误
def sefl(clean):
start_number=self.cleaned_data.get("start_number",None)
end_number=self.cleaned_data.get("end_number",None)
latest_start=max(start_number, end_number)
earliest_end = min(start_number, end_number)
delta = (earliest_end - latest_start) + 1
if delta is None:
raise ValidationError("overlap not allowed")
您需要捕获正在创建的 none 值,如下所示:
def sefl(clean):
start_number = self.cleaned_data.get("start_number", None)
end_number = self.cleaned_data.get("end_number", None)
if start_number is not None and end_number is not None:
latest_start=max(start_number, end_number)
earliest_end = min(start_number, end_bbch)
delta = (earliest_end - latest_start) + 1
if delta is None:
raise ValidationError("overlap not allowed")
else:
raise ValidationError("start_number and end_number are required")
这是因为您将两个变量的默认值定义为 None
。如果在 max
或 min
进行比较时,其中至少有一个实际上是 None
,则会出现您遇到的问题。
如果您有兴趣,有几种解决方法。例如,如果有合适的值,您可以使用不同的默认值而不是 None
。
您好,我在验证检查中遇到了这个错误
def sefl(clean):
start_number=self.cleaned_data.get("start_number",None)
end_number=self.cleaned_data.get("end_number",None)
latest_start=max(start_number, end_number)
earliest_end = min(start_number, end_number)
delta = (earliest_end - latest_start) + 1
if delta is None:
raise ValidationError("overlap not allowed")
您需要捕获正在创建的 none 值,如下所示:
def sefl(clean):
start_number = self.cleaned_data.get("start_number", None)
end_number = self.cleaned_data.get("end_number", None)
if start_number is not None and end_number is not None:
latest_start=max(start_number, end_number)
earliest_end = min(start_number, end_bbch)
delta = (earliest_end - latest_start) + 1
if delta is None:
raise ValidationError("overlap not allowed")
else:
raise ValidationError("start_number and end_number are required")
这是因为您将两个变量的默认值定义为 None
。如果在 max
或 min
进行比较时,其中至少有一个实际上是 None
,则会出现您遇到的问题。
如果您有兴趣,有几种解决方法。例如,如果有合适的值,您可以使用不同的默认值而不是 None
。