【发布时间】:2017-10-06 12:56:34
【问题描述】:
我需要覆盖 Django 模型表单中的 clean() 方法,以对输入的数据执行额外的唯一性检查。
此页面提供了实现细节: https://docs.djangoproject.com/en/1.11/ref/forms/validation/复制到这里:
def clean(self):
cleaned_data = super(ContactForm, self).clean()
cc_myself = cleaned_data.get("cc_myself")
subject = cleaned_data.get("subject")
if cc_myself and subject:
# Only do something if both fields are valid so far.
if "help" not in subject:
raise forms.ValidationError(
"Did not send for 'help' in the subject despite "
"CC'ing yourself."
)
但是我很困惑为什么这个方法在函数的末尾没有return cleaned_data?确定这是正确的做法吗?
【问题讨论】:
标签: python django django-forms