Django:如何显示不是特定于字段的验证错误? [英] Django: How to display Validation errors not specific to a field?

查看:113
本文介绍了Django:如何显示不是特定于字段的验证错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单的干净方法中提出错误(不绑定到字段)。

I have errors raised in the form's clean method (not tied to a field).

如何在模板中显示?

我尝试过{{forms.errors}}和{ {form.non_field_errors}},但没有工作。

I tried {{ forms.errors }} and {{ form.non_field_errors }} but neither worked.

推荐答案

根据 docs ,他们进入特殊字段( __ all __ ),应该可通过 non_field_errors()方法访问。猜测,我会说这个方法返回一个序列。

According to the docs, they go in a special field (__all__) and should be accessed via the non_field_errors() method. At a guess, I'd say that method returns a sequence.

这篇关于Django:如何显示不是特定于字段的验证错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆