Flask – Complete Web Development Guide

Learn Flask from fundamentals to real-world usage, including workflow, commands, folder structure, and best practices.

1️⃣ What is Flask?

Flask is a lightweight (micro) web framework written in Python. It provides the core tools needed to build web applications without enforcing strict project structure.

Micro Framework means:

  • No built-in ORM
  • No built-in admin panel
  • Only routing, request handling, and templating

2️⃣ Why Use Flask?

3️⃣ When to Use Flask?

Use Case Flask Suitable?
Small web apps ✅ Yes
REST APIs ✅ Yes
ML model serving ✅ Yes
Enterprise monolith apps ❌ No (Use Django)

4️⃣ Flask Workflow (How It Works)

  1. User sends HTTP request (Browser/Postman)
  2. Flask receives request
  3. URL routing matches a function
  4. Python logic executes
  5. Response returned to user
User → Request → Flask Route → Python Function → Response → Browser
    

5️⃣ Installation & Setup

Create Virtual Environment

python -m venv venv
venv\Scripts\activate
    

Install Flask

pip install flask
    

6️⃣ Basic Flask App

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello Flask!"

if __name__ == "__main__":
    app.run(debug=True)
    

7️⃣ Flask Folder Structure

Basic Structure

project/
│── app.py
│── venv/
    

Professional Structure

project/
│── app/
│   ├── __init__.py
│   ├── routes.py
│   ├── models.py
│   ├── templates/
│   └── static/
│── config.py
│── run.py
│── venv/
    

8️⃣ Real-World Flask Use Cases

🔗 External Learning Resources