[Django]-Is client side validation nessesary in Django?

2👍

Client side validation may improve user experience (less page reloads). It may decrease number of hits to he server (but sometimes this number is increased :). But it is not necessary.

Anyway server side validation is a must. You can’t trust data from user input.

3👍

If you have a web application that faces the public internet client side, validation is pretty much a user expectation. You might be able to ignore this if volume is low and people are motivated to use your website.

For an company intranet site, the additional development cost may weigh against client side validation. However, if you use an available client framework (e.g. jquery or django-parsley) the additional cost for client side validation is actually fairly small and likely worth the effort in intraweb applications.

ADDED

Yes, as others had already stated client-side only validation is very bad as it is the same as no validation — you can coerce the browser to send whatever you want back to the server.

You can do also do lots of nice things client side that you cannot server side. Sometimes these are closely related to client side validation.

E.g., limiting a comment to 500 characters. With client side code you can display a characters remaining count on screen — with a little planning this can be integrated with the validation code.

2👍

This is largely a matter of opinion, but I would have to say no – you don’t need to implement client-side validation. Especially when you can get all of the errors from your Django form returned as JSON via a simple Ajax POST.

Django forms already do an excellent job of validating input, so why add yet more code you have to maintain in two places that does the same thing? You absolutely MUST do server-side validation anyway, so why not just do it all in one place?

Additionally, if you don’t implement the same validations on the server as on the client, or worse – only do client-side validation, someone can always turn JavaScript off in the browser and possibly bypass your validation(s) or allow junk data to get into your database if you’re not careful.

Leave a comment