2013-06-03 52 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也有助於