通知错误

时间:2013-06-03 16:45:44

标签: django django-admin

有没有办法在管理网站中启动自定义错误?:

enter image description here

目前我用

抛出错误
raise forms.ValidationError('error')

但显示调试错误屏幕

1 个答案:

答案 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也可以提供帮助