Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Django, how do i change "This field is required." to "Name is required"?

I'm using the forms framework. And when I set required=True, this error shows. What if I don't want it to say "This field", but instead, say the label?

Since i'm not going to be displaying it beneath the form input. I"m going to display all the errors at the top of the page.

like image 406
TIMEX Avatar asked Dec 16 '10 23:12

TIMEX


1 Answers

An easy way to specify simple "required" validation messages is to pass the field the error_messages argument.

name = forms.CharField(error_messages={'required': 'Your Name is Required'}) 

Check the docs for which keys can be specified per field: http://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.Field.error_messages

For anything else, you're going to need real form validation which means you'd be writing error messages anyways!

like image 125
Yuji 'Tomita' Tomita Avatar answered Oct 27 '22 00:10

Yuji 'Tomita' Tomita