How to display Chinese prompts in DateField of wtform

class RegisterForm(Form):
    name = simple.StringField(
            label="",
            validators=[
                validators.DataRequired(message="")
            ],
            widget=widgets.TextInput(),
            render_kw={"class": "form-control"},
    )

    birthday = core.DateField(label="", format="%Y-%m-%d")   

ask for advice:

after rendering the page
if birthday does not fill in the time format, the prompt is "Not a valid date value"
how can this be changed to custom Chinese?

Apr.08,2021

to completely overwrite the error message, inherit the DateField and override the process_formdate () method, such as

-sharp -*- coding: utf-8 -*-
from wtforms import Form, DateField
from webob.multidict import MultiDict


class DemoDateField(DateField):
    def process_formdata(self, valuelist):
        try:
            DateField.process_formdata(self, valuelist)
        except ValueError:
            raise ValueError(u'')


class DemoForm(Form):
    day = DemoDateField('day')


form = DemoForm()
form.process(MultiDict(dict(day='abc')))
assert form.day.process_errors == [u'']

if you just translate English error messages, modify the locale setting or inherit the DateField and override the gettext () method.

Menu