How to return 400 (Bad Request) on Flask?

You have a variety of options: The most basic: @app.route(“https://stackoverflow.com/”) def index(): return “Record not found”, 400 If you want to access the headers, you can grab the response object: @app.route(“https://stackoverflow.com/”) def index(): resp = make_response(“Record not found”, 400) resp.headers[‘X-Something’] = ‘A value’ return resp Or you can make it more explicit, and not just … Read more

What is the cause of the Bad Request Error when submitting form in Flask application?

The solution was simple and uncovered in the comments. As addressed in this question, Form sending error, Flask, and pointed out by Sean Vieira, …the issue is that Flask raises an HTTP error when it fails to find a key in the args and form dictionaries. What Flask assumes by default is that if you … Read more