Back to Writing
NOTESflaskpythonapplication-factoryweb-dev

Flask - Application Factory Pattern with create_app

December 14, 2020Updated Feb 17, 2026

![](

Ug.CqvuToxIYOejOKK18lDTJmDERP7pEMkuaWVeLyjlWaYg.JPEG.cdw0424/SE-d2c87d70-89c3-41d8-ac39-585c2496ffc4.jpg?type=w966)

This post summarizes content from "Do it! Jump to Flask."

Sincere thanks to author Park Eung-yong and publisher "EasySpub" for making this content possible.

Do it! Jump to Flask

![](

OF27llCytbyDSvj15Ug.ER2UYPxjmGUq1tbAkhGfFvwDUd81z3RMS9ITno_MVGwg.PNG.cdw0424/image.png?type=w966)

Note: __init__ is a Python-designated function name that automatically runs first when a module (folder) is executed.

from flask import Flask

# create_app is the application factory function designated by Flask.
# What Flask calls an "application factory" refers to a function that creates the app object.
# The reason for creating the app object inside a function (i.e., via the application factory)
# is to prevent global access to the app object, avoiding circular imports.
def create_app():

app = Flask(__name__)

@app.route('/')
def hello_pybo():
return 'Hello, Pybo!'

return app


Do it! Jump to Flask