Processing Django Form Errors

Say, you are returning an ajax response to the submission of a form. If you had pre-submission javascript based validation, you might be able to fix some form errors beforehand. But the best practice would be to also rely on django form for backend validation and throw back the validation error messages.

You can structure your response in any way you want but the most common case would be to send all the errors in a dictionary format. Here’s a code snippet to do that:

    dict([(field, [unicode(error) for error in errors]) for field, errors in form.errors.items()])

Posted by tarequeh on 2 Sept. 2009

Please sign in using your OpenID to comment.

0 Comments