从django中删除会形成验证错误(removing from django forms validation errors)

编程入门 行业动态 更新时间:2024-10-28 04:21:38
从django中删除会形成验证错误(removing from django forms validation errors)

在Django中,{{form.field.errors}}给出了字段的验证错误。 但它始终将其显示为无序列表()。 但我只是想要错误信息。 有没有办法得到错误信息?

In Django the {{ form.field.errors }} gives the validation error for a field. But it always displays it as unordered list (). But I just want the error message. Is there a way to get the error message?

最满意答案

{% for error in field.errors %}使用{% for error in field.errors %}然后逐个输出每个错误,这将只生成包含消息的字符串而不是无序列表。 文档解释了这个:

http://docs.djangoproject.com/en/1.0/topics/forms/

Use {% for error in field.errors %} and then output each error one by one, this will produce just the string containing the message rather than an unordered list. The docs explain this:

http://docs.djangoproject.com/en/1.0/topics/forms/

更多推荐

本文发布于:2023-07-14 17:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106064.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   removing   django   errors   validation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!