0

I am trying to fetch date from html form into flask web application.

<input type="date" name="startdate">(html)

startdate = datetime.date(request.form['startdate'])(python-flask)

I am getting an error

File "C:\ProgramData\Anaconda3\lib\site-packages\werkzeug\datastructures.py", line 431, in getitem raise exceptions.BadRequestKeyError(key) werkzeug.exceptions.HTTPException.wrap..newcls: 400 Bad Request: KeyError: 'startdate'

ronit yadav
  • 1
  • 1
  • 2

1 Answers1

1

When you fetch date from input field (type=date), You will always receive date in string format (yyyy-mm-dd), and you can parse this directly as follows:

from datetime import datetime
startdate = datetime.datetime.strptime(
                     request.form['startdate'],
                     '%Y-%m-%d')
Alwyn Miranda
  • 370
  • 3
  • 5
  • 18