Labs ICT
โญ Pro Login

Project Structure

Organizing Flask projects the right way.

Project Structure

As your Flask app grows beyond a single file, you'll want a clean project layout. Here's the standard structure that most Flask projects follow:

my_project/
    venv/
    app.py
    config.py
    requirements.txt
    static/
        css/
            style.css
        js/
            script.js
        images/
    templates/
        base.html
        index.html
        about.html

The app.py file is your entry point. It creates the Flask instance, registers blueprints, and starts the server. Keep it clean โ€” put business logic elsewhere.

The templates/ directory holds your HTML files. Flask uses Jinja2 by default, and it looks for templates in this folder. The static/ directory is where CSS, JavaScript, images, and other assets live. Flask serves these files automatically at the /static URL path.

The requirements.txt file tracks your dependencies so anyone can recreate your environment with pip install -r requirements.txt.

For configuration, a separate config.py keeps settings organized:

import os

class Config:
    SECRET_KEY = os.environ.get("SECRET_KEY", "dev-key-change-me")
    DEBUG = False

class DevelopmentConfig(Config):
    DEBUG = True

class ProductionConfig(Config):
    DEBUG = False

As projects get bigger, blueprints help you split functionality into separate modules. Each blueprint can have its own routes, templates, and static files. It's Flask's way of keeping things modular without forcing you into a rigid structure.

๐Ÿงช Quick Quiz

Where do HTML templates go?