0
如何在模型clean
方法中提高ValidationException
?提高模型清潔方法中的字段錯誤
def clean(self):
from django.core.exceptions import ValidationError
raise ValidationError({'title': 'not ok'})
上面(使用形式時)未在錯誤添加到title
領域,但對非字段的錯誤。
我知道怎麼做了一個表格(self._errors['title'] = self.error_class([msg])
)內,但self._errors
不車型內部存在clean
方法。
是的,我也試過。但它似乎必須使用'validators = [clean_title]'來連接字段本身,因此'clean_title'必須在字段之前定義(或必須導入)。不是很方便。 – Zardoz