Flask-Pretty is a Flask extension to output prettified HTML pages to ease the development process of HTML templates. However, HTML prettifying should only be used for development purposes only. For production purposes, HTML minifying should be used instead (for instance by using Flask-HTMLmin).

The underlying HTML prettifying process is provided by BeautifulSoup.


Install the extension with with pipenv (recommended):

$ pipenv install flask-pretty

Or with pip:

$ pip install flask-pretty


Using Flask-Pretty is really simple:

import Flask
from flask_pretty import Prettify

app = Flask(__name__)
prettify = Prettify(app)

Or if you are using the Flask Application Factories pattern:

import Flask
from flask_pretty import Prettify

prettify = Prettify()

def create_app():
    app = Flask(__name__)

Flask-Pretty is configurable via the following configuration variables:

  • PRETTIFY: enable Flask-Pretty for all routes (default: False)


class flask_pretty.Prettify(app=None)

Primary class container for HTML pages prettifying.

After each request, if the route is returning an HTML page, it will be minified using BeautifulSoup.prettify feature.

You can initialize Prettify like this:

prettify = Prettify()

Then pass the application object to be configured:


You must explicitly enable Flask-Pretty by setting PRETTIFY to True when necessary (e.g. in development mode only).


Initializes a Flask object app: binds the HTML prettifying with app.after_request.

Parameters:app – The Flask application object.