Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Application Factory

from flask import Flask

def create_app():
    app = Flask(__name__)

    @app.route('/')
    def main():
        return 'Hello World!'

    return app


flask --app myapp --debug run
import myapp

def test_app():
    web = myapp.create_app().test_client()

    rv = web.get('/')
    assert rv.status == '200 OK'
    assert rv.data.decode('utf-8') == 'Hello World!'