Return HTTP status code 201 in flask

You can use Response to return any http status code.

> from flask import Response
> return Response("{'a':'b'}", status=201, mimetype='application/json')

You can read about it here.

return render_template('page.html'), 201

You can do

result = {'a': 'b'}
return result, 201

if you want to return a JSON data in the response along with the error code You can read about responses here and here for make_response API details


As lacks suggested send status code in return statement and if you are storing it in some variable like

notfound = 404
invalid = 403
ok = 200

and using

return xyz, notfound

than time make sure its type is int not str. as I faced this small issue also here is list of status code followed globally http://www.w3.org/Protocols/HTTP/HTRESP.html

Hope it helps.