开发者

Accessing a form field 'error' on view

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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜