Handling basic configurations

The first thing that comes to mind is configuring a Flask application as per the need. In this recipe, we will try to understand the different ways in which Flask configurations can be done.

Getting ready

In Flask, a configuration is done on an attribute named config of the Flask object. The config attribute is a subclass of the dictionary data type, and we can modify it just like any dictionary.

How to do it…

For instance, to run our application in the debug mode, we can write the following:

app = Flask(__name__)
app.config['DEBUG'] = True

Tip

The debug Boolean can also be set at the Flask object level rather than at the config level:

app.debug = True

Alternatively, we can use this line of code:

app.run(debug=True)

Enabling ...

Get Flask Framework Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.