Search code examples
pythondjangocode-duplicationclient-side-validationserver-side-validation

Django: Avoiding Server-Side and Client-Side Validation Code Duplication


How do you avoid duplicating validation code on the server-side and on the client-side with Django?

Given that Django follows a Don't Repeat Yourself principle, it seems logical that there would be a way to do this, but I have no idea how.


Solution

  • Here's an uncompleted ("alpha grade") project that addresses your problem: http://eikke.com/django-validation-an-introduction/ :

    So I’ve been thinking since some time to create a Django templatetag which allows one to generate client-side Javascript form validation code without writing any code himself (unless using custom widgets).... The resulting project is called django-validation.

    (And see also Django ticket #19)