开发者

Accessing a form field 'error' on view

开发者 https://www.devze.com 2023-03-16 12:46 出处:网络
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)).

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

精彩评论

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