I want to know in my view, if a certain field raised an error, that way I can send some values to the template (index of current tab (using a javascript tab widget)). Is it possible?
Thanks i开发者_如何转开发n advance.
You can definitely access your form errors in your view. Each bound Form instance has an errors attribute that gives you a dictionary mapping field name to error-message lists:
>>> f = ContactForm({'subject': 'Hello', 'message':''})
>>> f.errors
{'message':[u'This field is required.']}
You can access individual fields as follows:
>>> if f['subject'].errors:
values = [Add values to send to template]
精彩评论