Learn Flask from fundamentals to real-world usage, including workflow, commands, folder structure, and best practices.
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:
| Use Case | Flask Suitable? |
|---|---|
| Small web apps | ✅ Yes |
| REST APIs | ✅ Yes |
| ML model serving | ✅ Yes |
| Enterprise monolith apps | ❌ No (Use Django) |
User → Request → Flask Route → Python Function → Response → Browser
Create Virtual Environment
python -m venv venv
venv\Scripts\activate
Install Flask
pip install flask
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello Flask!"
if __name__ == "__main__":
app.run(debug=True)
project/
│── app.py
│── venv/
project/
│── app/
│ ├── __init__.py
│ ├── routes.py
│ ├── models.py
│ ├── templates/
│ └── static/
│── config.py
│── run.py
│── venv/