Home > Blockchain >  datetime-local returns NoneType when it is post to flask
datetime-local returns NoneType when it is post to flask

Time:10-22

I would like the user to input the DateTime and Flask app to get this info, but "DateTime-local" returns None when it is posted to Flask

HTML:

    <form action="/" method="POST">
        <div style=font-size:15px; font-weight:bold; mergin-left:150px;>
            <p>start<br><input type="datetime-local",name="time_start"></p>
            <p>end<br><input type="datetime-local",name="time_end"></p>
            <p><input type="submit" value="submit"></p>
        </div>
    </form>

Flask:

@app.route('/',methods=["GET","POST"])
def hello_world():
    if request.method == "POST":
        st=request.form.get("time_start")
        ed=request.form.get("time_end")
        print(st,type(st))
        print(ed,type(ed))

that returns:

None <class 'NoneType'>
None <class 'NoneType'>

I don't understand why... Could anyone help me get the DateTime value from HTML? I tried Chrome and Edge browser, neither worked.

CodePudding user response:

Now I found a solution. Setting 'value' attribute (as the default time) returns the expected value.

<input type="datetime-local" value="2021-10-19T10:00">            
  • Related