在Django中,我如何更改“这个字段是必需的”。到“名称是必需的”? [英] In Django, how do i change "This field is required." to "Name is required"?
问题描述
由于我不会在表单下面显示它输入。我将显示页面顶部的所有错误。
一个简单的方法来指定简单的必需验证消息是将该字段传递给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屋!