Setting HTTP status code in Bottle?
Bottle's built-in response type handles status codes gracefully. Consider something like:
return bottle.HTTPResponse(status=300, body=theBody)
As in:
import jsonfrom bottle import HTTPResponse@route('/')def f(): theBody = json.dumps({'hello': 'world'}) # you seem to want a JSON response return bottle.HTTPResponse(status=300, body=theBody)
raise can be use to get more power with HTTPResponse to show the status code (200,302,401):
Like you can simply do this way:
import jsonfrom bottle import HTTPResponseresponse={}headers = {'Content-type': 'application/json'}response['status'] ="Success"response['message']="Hello World."result = json.dumps(response,headers)raise HTTPResponse(result,status=200,headers=headers)