Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'id'

Tags:

rest

post

flask

api

html page

{%block title%}Login page{% endblock %}

{%block content%}
<form action = '#' method="post">
   <p>creds:</p>
   <p><input type="number"  placeholder="id"  Id="id" /></p>
   <p><input type="text"  placeholder="nm"  name="nm" /></p>
   <p><input type="submit" value="submit" /></p>
</form>
{%endblock%}

app code

@app.route("/")
def home():
    return render_template("login.html")

@app.route("/",methods = ["POST","GET"])
def post():
    if request.method == "POST":
        user = request.form['nm']
        id = request.form['id']
        sql = ('''INSERT INTO abc
                (id, name) VALUES (?, ?)
                ''')
        val = (id,user)
        cur.execute (sql, val)
    return 'Ok'

i tried using return.form.get('id') but its returning null

Can anyone please help me on this

Thanks

like image 492
younus Avatar asked Dec 17 '22 14:12

younus


1 Answers

<p><input type="number"  placeholder="id"  name="id" /></p>

you have typed Id instead of name

like image 185
Swapnil Suryawanshi Avatar answered Apr 28 '23 21:04

Swapnil Suryawanshi