Home > Blockchain >  Flask WT Forms DateTimeLocal Field is not sending data
Flask WT Forms DateTimeLocal Field is not sending data

Time:10-29

I'm trying to implement DateTimeLocalField in Flask WT Forms however the field does not return data. The other fields work fine.

from flask_wtf import FlaskForm
from wtforms.fields import DateTimeLocalField

class AddLegForm(FlaskForm):
    origin_datetime = DateTimeLocalField('Origin Time')

In views.py:

@loads_blueprint.route('/add_leg/<load_id>', methods=['GET', 'POST'])
@login_required
def add_leg(load_id):    
    leg = db.session.query(Legs)
    form = AddLegForm()   
    print(type(form.origin_datetime.data))
    print(form.origin_datetime.data)

The print statements show:

<class 'NoneType'>
None

There are also StringField's in my form and all of the other data is there.

Minimal HTML:

  <form method="POST", action="/loads/add_leg/{{load_id}}">        
    {{ form.hidden_tag() }}  
    <div >          
      {{ form.origin_datetime.label }} 
      {{ form.origin_datetime(class_="form-control", size=32) }}
    </div>
    <button type="submit" >Submit</button>
  </form>

CodePudding user response:

It might be a format issue, what if you use:

origin_datetime = DateTimeLocalField('Origin Time', format='%Y-%m-%dT%H:%M')
  • Related