Skip to Content
Flask Web Development, 2nd Edition
book

Flask Web Development, 2nd Edition

by Miguel Grinberg
March 2018
Intermediate to advanced
312 pages
7h 22m
English
O'Reilly Media, Inc.
Book available
Content preview from Flask Web Development, 2nd Edition

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, production 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. These include 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. Instead, a command that performs all the required tasks can be added to flasky.py.

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

Example 17-1. flasky.py: deploy command
from flask_migrate import upgrade
from app.models import Role, User

@manager.command
def deploy():
    """Run deployment tasks."""
    # migrate database to latest revision
    upgrade()

    # create or update user roles
    Role.insert_roles()

    # ensure all users are following themselves
    User.add_self_follows()

The functions invoked by this command were all created before; they are just invoked all together from a single command to simplify the deployment of the application.

Tip

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Flask Web Development - Second Edition

Mastering Flask Web Development - Second Edition

Daniel Gaspar, Jack Stouffer

Publisher Resources

ISBN: 9781491991725Errata Page