Created
June 28, 2012 08:41
-
-
Save rdandy/3009951 to your computer and use it in GitHub Desktop.
use this __init__() for display custom error messages in django forms.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyForm(forms.Form): | |
username = forms.CharField(label=_('Your username'), min_length=3, max_length=30) | |
email = forms.EmailField(label=_('Your email address'), min_length=3, max_length=30) | |
def __init__(self, *args, **kwargs): | |
super(MyForm, self).__init__(*args, **kwargs) | |
for field in self.fields.values(): | |
field.error_messages = { | |
'required': ugettext('The field : {fieldname} is required !!').format(fieldname=field.label), | |
'invalid': ugettext('The field : {fieldname} is invalid !!').format(fieldname=field.label) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment