Chapter 17. Deployment

The web development server that comes bundled with Flask is not robust, secure, or efficient enough to work in a production environment. In this chapter, deployment options for Flask applications are examined.

Deployment Workflow

Regardless of the hosting method used, there are a series of tasks that must be carried out when the application is installed on a production server. The best example is the creation or update of the database tables.

Having to run these tasks manually each time the application is installed or upgraded is error prone and time consuming, so instead a command that performs all the required tasks can be added to

Example 17-1 shows a deploy command implementation that is appropriate for Flasky.

Example 17-1. deploy command
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    # migrate database to latest revision

    # create user roles

    # create self-follows for all users

The functions invoked by this command were all created before; they are just invoked all together.


If you have cloned the application’s Git repository on GitHub, you can run git checkout 17a to check out this version of the application.

These functions are all designed in a way that causes no problems if they are executed multiple times. Designing update functions in this way makes it possible to run just this deploy command every ...

Get Flask Web Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.