Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable debug mode in Flask in production mode

Tags:

python

flask

In bottle all i have to do to enable debug mode is:

from bottle import debug

application = Bottle()
app = application
debug(True)

How can i do the same in Flask framework?

like image 275
Νικόλαος Βέργος Avatar asked Oct 02 '18 08:10

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


People also ask

How do I turn on debug mode on Flask?

If you click on the “Run and Debug” icon on the left hand side of the IDE or alternatively type Ctrl+Shift+D you will see the “RUN AND DEBUG” window. Now click on the “create a launch. json file” link and when prompted to “Select a debug configuration” choose “Python File Debug the currently active Python file”.

What is debug mode in Flask?

Flask Debug mode allows developers to locate any possible error and as well the location of the error, by logging a traceback of the error. The Flask debug mode also enables developers to interactively run arbitrary python codes, so that one can resolve and get to the root cause on why an error happened.

How do you debug a Flask application in the development server?

Command Line The flask run CLI command is the recommended way to run the development server. Use the --app option to point to your application, and the --debug option to enable debug mode.

Can I use Flask run in production?

Although Flask has a built-in web server, as we all know, it's not suitable for production and needs to be put behind a real web server able to communicate with Flask through a WSGI protocol.


1 Answers

To enable the debug mode I would add the following code to the flask app:

app.config['ENV'] = 'development'
app.config['DEBUG'] = True
app.config['TESTING'] = True

I would also sugest setting environment variables for the environment and debug.

$ export FLASK_ENV=development 
$ export FLASK_DEBUG=1
like image 147
Gil Sousa Avatar answered Sep 28 '22 07:09

Gil Sousa