有没有办法在管理网站中启动自定义错误?:
目前我用
抛出错误raise forms.ValidationError('error')
但显示调试错误屏幕
答案 0 :(得分:0)
你把raise forms.ValidationError('error')
放在哪里?
在表单中,clean()方法是引发自定义错误的好地方。您甚至可以def clean_fieldname()
为一个字段执行特定验证。来自django docs
from django import forms
class ContactForm(forms.Form):
# Everything as before.
...
def clean_recipients(self):
data = self.cleaned_data['recipients']
if "fred@example.com" not in data:
raise forms.ValidationError("You have forgotten about Fred!")
# Always return the cleaned data, whether you have changed it or
# not.
return data
此link也可以提供帮助