Skip to content

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

This is okay for “Hello World”, but it gets messy fast.

myapp/
  app.py
  templates/
    home.html
  static/
    styles.css
myapp/
  app.py
  templates/
    home.html
  static/
    styles.css

Flask 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 gunicorn
myapp/
  __init__.py          # create_app() lives here
  routes.py            # routes / views
  models.py            # database models
  templates/
  static/
config.py
wsgi.py                # entrypoint for gunicorn

Why 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 coffee

Was this page helpful?

Let us know how we did