2013-06-03 33 views
0

有什么办法在管理网站那样?:推出自定义错误通知错误

enter image description here

目前我把与

raise forms.ValidationError('error') 

但错误显示调试错误屏幕

+0

http://stackoverflow.com/questions/2967110/django-validation-error-in-admin应该给你一个想法 – karthikr

回答

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 "[email protected]" 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也有助于