1

I am making a small project - Reminider System. I have a form which accepts values from users and inserts into the database table. The problem is occurring while fetching a value from a textbox. Below is my code and also I am giving what error am getting.

<form method="POST" action="">
<input type="hidden" name="unique" value="{{session.UID}}" disabled="true">
<button type="submit" class="btn btn-primary">Confirm</button>
</form>

This is my template

@app.route('/home/set_reminder',methods=['POST'])
@is_logged_in
def set_reminder():
    if request.method=='POST' and form.validate():
        uid = request.form['unique']

I am getting the error in this line uid = request.form['unique']. Not getting why it cannot fetch the value.

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

And this is the error which am getting. Please help me out.

Barefaced Bear
  • 688
  • 1
  • 9
  • 30

1 Answers1

1

In your html, the uid input is disabled, so the browser will not send uid in a POST request's body. This causes the error when you try to access request.form.uid - it doesn't exist.

You could use readonly rather than disabled if the value must be returned by the browser.

See this answer for a little more information on BadRequestKeyError.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153