DateField is not rendered as type="date"

anvd picture anvd · Oct 25, 2013 · Viewed 7.9k times · Source
class Form(Form):
      plan_start = DateField('Plan Start', validators=[Required()]) 

this code will render this html.

<input id="plan_start" name="plan_start" type="text" value="">

My question is: why the type is text and not date?

I only can get this resolved by passing explicitly the type='date' in template.

 {% raw form.plan_start.label %}{% raw form.plan_start(type='date') %}

Answer

snahor picture snahor · Nov 4, 2013

You can use the DateField from html5.

from wtforms.fields.html5 import DateField


class Form(Form):
    plan_start = DateField('Plan Start', validators=[Required()])