From the course: Building React and Django Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Validating form data with Django REST framework

Validating form data with Django REST framework

From the course: Building React and Django Apps

Start my 1-month free trial

Validating form data with Django REST framework

- [Instructor] Right now, the validation is simple, whether or not a form is filled out. Let's do something a bit more useful. Let's check for a specific street address format. In the booking serializer, we're going to add a street address error message. In a Django REST framework serializer, you only have to prefix the field name with validate in order to implement custom validation for the field. We can define a regular expression that we want to match, which will be a number followed by a street name and any other suffix and if the street address that's filled out matches, we simply return that value. Otherwise, we raise a validation error.

Contents