You may be used to customize the response information configured flask.make_response
In response to a text configuration information, status code 404
response
JSON response data, status code 200
Return html
Coding #: UTF-. 8
from the Flask Flask Import, make_response, the render_template
Import JSON
App = the Flask (name__ __)
@ app.route ( "/ RP /")
DEF send_response ():
"" "configured response object" ""
RESP = make_response ( "index", 404) # custom content and status codes
resp.headers [ 'the content-type'] = 'text / Plain'
# returns JSON
# RESP = make_response (json.dumps ({ 'name': 'Tom' }), 200) and # custom content status codes
# resp.headers [ 'the content-type'] = 'file application / JSON'
# returns the HTML
# make_response RESP = () # custom content and status codes
# resp.respones = the render_template ( "index.html")
# resp.headers [ 'the Content-type'] = 'text / HTML'
# # resp.status = '200'
# resp.status_code = 200
return resp
if __name__ == '__main__':
app.run(debug=True)