在Django中,我如何更改“这个字段是必需的”。到“名称是必需的”? [英] In Django, how do i change "This field is required." to "Name is required"?

查看:172
本文介绍了在Django中,我如何更改“这个字段是必需的”。到“名称是必需的”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用表单框架。当我设置required = True时,这个错误显示。如果我不想让它说这个字段,而是说标签呢?



由于我不会在表单下面显示它输入。我将显示页面顶部的所有错误。

解决方案

一个简单的方法来指定简单的必需验证消息是将该字段传递给error_messages参数。

  name = forms.CharField(error_messages = {'required':'您的名称是必需的}} 

检查每个字段可以指定哪些键的文档:
http://docs.djangoproject.com /en/dev/ref/forms/fields/#django.forms.Field.error_messages



对于其他任何东西,你将需要真正的形式验证这意味着你会写错误信息!


I'm using the forms framework. And when I set required=True, this error shows. What if I don't want it to say "This field", but instead, say the label?

Since i'm not going to be displaying it beneath the form input. I"m going to display all the errors at the top of the page.

解决方案

An easy way to specify simple "required" validation messages is to pass the field the error_messages argument.

name = forms.CharField(error_messages={'required': 'Your Name is Required'}) 

Check the docs for which keys can be specified per field: http://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.Field.error_messages

For anything else, you're going to need real form validation which means you'd be writing error messages anyways!

这篇关于在Django中,我如何更改“这个字段是必需的”。到“名称是必需的”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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