DateForm Python-Flask - [u'Not a valid date value']} -


i'm developing web app , @ point want create new entry politic table. until had add dates. form isnt accepting input due wrong date format. lets it..

i have form:

class politicform(flaskform):   publicname = stringfield('public name', validators=[datarequired("please enter politician public name.")])   completename = stringfield('complete name', validators=[datarequired("please enter politician complete name.")])   startdate = datefield('start date', format='%m-%d-%y', validators=[datarequired("please enter politician start date.")])   enddate = datefield('end date', format='%m-%d-%y', validators=(validators.optional(),))   submit = submitfield('add politician', validators=(validators.optional(),)) 

but somehow datefield isnt right because form can't validate startdate field nor enddate field. create function:

@app.route("/create_politician", methods=["get", "post"]) @login_required def create_politician():   form = politicform()    if request.method == "post":     print form.validate()     flash(form.errors)     if form.validate() == false:       return render_template('createpolitician.html', form=form)     else:       print form.startdate.data       newpolitician = politic(form.publicname.data, form.completename.data, form.startdate.data, form.enddate.data)       print form.startdate.data       db.session.add(newpolitician)       db.session.commit()       return redirect(url_for('home'))    elif request.method == "get":     return render_template("createpolitician.html", form=form) 

and on flash(form.errors)
following:

{'startdate': ['please enter politician start date.'], 'enddate': [u'not valid date value']}

models.py

class politic(db.model):   __searchable__ = ['publicname', 'completename']   __tablename__ = 'politics'    idpolitician = db.column(db.integer, primary_key=true)   publicname = db.column(db.string(150))   completename = db.column(db.string(300))   startdate = db.column(db.date)   enddate = db.column(db.date)    def __init__(self, publicname, completename, startdate, enddate):     self.publicname = publicname.title()     self.completename = completename.title() 

.html

<form method="post" action="/create_politician">         {{ form.hidden_tag() }}          <div class="form-group">           {{ form.publicname.label }}           {{ form.publicname }}         </div>          <div class="form-group">           {{ form.completename.label }}           {{ form.completename }}         </div>          <div class="form-group">           {{ form.startdate.label }}           {{ form.startdate }}         </div>          <div class="form-group">           {{ form.enddate.label }}           {{ form.enddate }}         </div>          {{ form.submit(class="btn-primary") }}        </form> 

any idea, wrong. there way format date input in order match form asking for?

thank you

regards


Comments

Popular posts from this blog

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -