0 votes
in Python Flask by
How to debug a Flask Application?

1 Answer

0 votes
by

Flask comes with a development server, and the development server has a Debug Mode. The Debug mode can be set to true when we call the run method of the Flask Application object.

Given below is an example.

from flask import Flask 

app = Flask(__name__)

app.run(host='127.0.0.1', debug=True)

However, we need to disable the debug mode before deploying the application on production to avoid full stack trace display in the browser. Such a stack trace can reveal a lot of essential details and is prone to exploitation by bad actors.

Further, we can make use of the Flask-DebugToolbar extension for easy debugging in the browser. We can also make use of Python’s pdb module and the debugging statement import pdb;pdb.set_trace() to support the debugging process.

...