David542
David542

Reputation: 110382

Creating error messages with Django/Javascript

From the tutorial in djangobook.com http://djangobook.com/en/2.0/chapter07/, I am creating a form which returns error messages to the user if the required fields are not filled out.

How does Django create these error messages? Is it using python or javascript?

What is the best practice for creating error messages -- should I create them in django or using straight javascript? Thank you.

Upvotes: 0

Views: 376

Answers (2)

A Lee
A Lee

Reputation: 8066

Yes, those error messages are being constructed on the Python side as Django is reconstructing your form page.

It's best to have server-side validation (on the Django side in your forms and form fields) and then add client-side as a progressive enhancement feature. Client-side validation is unreliable as there are many ways to get around it (disabling javascript, etc.) so you'll always need some kind of server side validation.

The jQuery validation plugin is a decent client-side javascript validation library if you're already using jQuery.

Upvotes: 1

hmontoliu
hmontoliu

Reputation: 4019

Without knowing what part of the djangobook are you referring (a link would be nice), I guess that probably you are referring to the validation that is done by django after checking the values retrieved in the POST or GET requests. Hence that validation is made with python in the server side.

Upvotes: 0

Related Questions