Flask Directory Structure
Flask lets you start with a single file, but real apps need structure.
A clean structure makes it easier to:
- scale your codebase
- write tests
- add Blueprints
- deploy reliably
Option 1: single-file starter (learning only)
app.pyapp.pyThis is okay for “Hello World”, but it gets messy fast.
Option 2: recommended starter package layout
myapp/
app.py
templates/
home.html
static/
styles.cssmyapp/
app.py
templates/
home.html
static/
styles.cssFlask will auto-discover templates/templates/ and static/static/ relative to your app.
Option 3: scalable layout (closer to production)
myapp/
__init__.py # create_app() lives here
routes.py # routes / views
models.py # database models
templates/
static/
config.py
wsgi.py # entrypoint for gunicornmyapp/
__init__.py # create_app() lives here
routes.py # routes / views
models.py # database models
templates/
static/
config.py
wsgi.py # entrypoint for gunicornWhy separate wsgi.pywsgi.py?
A typical production command is:
gunicorn "wsgi:app"gunicorn "wsgi:app"
So wsgi.pywsgi.py is an easy “server entry point”.
What’s next
In Phase 2 you’ll learn routing and views in depth.
In Phase 7 you’ll learn:
- Blueprints
- application factory pattern
Those concepts make Option 3 feel natural.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
