wtforms+flask today's date as a default value

后端 未结 1 573
盖世英雄少女心
盖世英雄少女心 2021-01-04 08:50

I did a small Flask app with a form with two date fields, and this is how I populate the values:

class BoringForm(Form):
    until = DateTimeField(\"Until\",         


        
相关标签:
1条回答
  • 2021-01-04 09:42

    Just drop the brackets on the callable:

    class BoringForm(Form):
        until = DateTimeField(
            "Until", format="%Y-%m-%dT%H:%M:%S",
            default=datetime.today, ## Now it will call it everytime.
            validators=[validators.DataRequired()]
        )
    
    0 讨论(0)
提交回复
热议问题