Fix Python – Return HTTP status code 201 in flask

Question

Asked By – ingh.am

We’re using Flask for one of our API’s and I was just wondering if anyone knew how to return a HTTP response 201?

For errors such as 404 we can call:

from flask import abort
abort(404)

But for 201 I get

LookupError: no exception for 201

Do I need to create my own exception like this in the docs?

Now we will see solution for issue: Return HTTP status code 201 in flask


Answer

You can read about it here.

return render_template('page.html'), 201

This question is answered By – Iacks

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0