[Flask] Flask server returns html response

Irtiza Ali iali at an10.io
Fri Dec 28 02:28:33 EST 2018


Thanks you guys, I'll check it out.

Regards
Irtiza Ali

On Thu, 27 Dec 2018, 18:53 Corey Boyle <coreybrett at gmail.com wrote:

> Perhaps setup an error handler that would return JSON?
>
>
> @main.app_errorhandler(500)
> def internal_server_error(e):
> """Handel 500 errors."""
> if (request.accept_mimetypes.accept_json and not
> request.accept_mimetypes.accept_html):
> 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/20181228/0c9de091/attachment.html>


More information about the Flask mailing list