[Flask] Flask server returns html response

Corey Boyle coreybrett at gmail.com
Thu Dec 27 08:52:48 EST 2018

Perhaps setup an error handler that would return JSON?

def internal_server_error(e):
"""Handel 500 errors."""
if (request.accept_mimetypes.accept_json and not
response = jsonify({'error': 'internal server error'})
response.status_code = 500
return response
return render_template('500.html'), 500

On Thu, Dec 27, 2018 at 7:10 AM Irtiza Ali <iali at an10.io> wrote:
> Hello everyone,
> I am a newbie in flask environment. I have built an api in flask,
everything works fine but when I pass an invalid request it returns html
response.  Can some please guide me to return json responses instead of
html ones. Thank you in advance.
> Regards
> Ali
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20181227/01d328ba/attachment.html>

More information about the Flask mailing list