Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show all errors in the browser on Flask framework?

I use Flask framework and build a Python project. It shows all errors on the page when I run a python file on the SSH shell.

After I installed WSGI to run the server automatically, it started not showing errors on the browser. It only shows "Internal Server Error" if there is an error.

my python file has this option at the end.

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=5000,debug=True)

I would like to look at all errors to figure out problems. Is there a way to look at all errors on the browser?

like image 455
Jake Avatar asked Dec 05 '13 09:12

Jake


People also ask

How do you check Flask errors?

When an error occurs in Flask, an appropriate HTTP status code will be returned. 400-499 indicate errors with the client's request data, or about the data requested. 500-599 indicate errors with the server or application itself. You might want to show custom error pages to the user when an error occurs.

How do you show error messages in Python?

To catch and print an exception that occurred in a code snippet, wrap it in an indented try block, followed by the command "except Exception as e" that catches the exception and saves its error message in string variable e . You can now print the error message with "print(e)" or use it for further processing.

How do I turn on debug on a Flask?

The debugger is enabled by default when the development server is run in debug mode. When running from Python code, passing debug=True enables debug mode, which is mostly equivalent.


2 Answers

I finally noticed that it doesn't show errors on the browser because I run the server under WSGI mod.

Python Flask shows detailed errors on the browser if I run the python file on the shell.

app.debug = True

This is a command to look at detailed errors.

So, I had to turn off WSGI mod to run python file to look at detailed errors that Flask supported.

like image 139
Jake Avatar answered Sep 28 '22 10:09

Jake


Please someone explain to me why the following approach doesnt display the erros in the browser which is what i want to do:

app = Flask(__name__)
app.debug = True
application = app

Its very tedieous task to always have to tail -f ../logs/error_log

like image 33
Νικόλαος Βέργος Avatar answered Sep 28 '22 12:09

Νικόλαος Βέργος