š Introduction
Ever wanted to build a website but didnāt feel like wrestling with JavaScript frameworks, or felt slightly terrified by Djangoās size and complexity?
Same.
Let me introduce you to Flaskāa lightweight Python web framework thatās easy to learn, beginner-friendly, and surprisingly powerful. With just a few lines of code, you can spin up a simple web app and start building actual stuff.
In this post, weāll talk about:
- What web frameworks are (and why you should care)
- What makes Flask so special
- How to get started with a simple āHello Worldā app
Letās dive in. š
š¤ What Are Web Frameworks?
Flask is a web framework. But what even is a web framework?
In simple terms, a web framework is a toolbox that helps developers build websites and web apps faster and with less pain.
Sure, if youāre building a basic personal page, some HTML, CSS, and a sprinkle of JavaScript might be enough. But once you want things like:
- User accounts
- Messaging between users
- Session management
- Dynamic content
⦠things get complicatedāfast.
A web framework handles all the annoying plumbing behind the scenes so you can focus on building features, not reinventing the wheel.
There are frontend frameworks (like React or Vue) and backend frameworks (like Flask or Django). Flask falls into the backend campāit helps you build the part of the website users donāt see, but that does all the heavy lifting.
š§Ŗ So, What Is Flask?
Flask is a Python-based micro web framework created by Armin Ronacher (legend). It was inspired by another framework called Bottle, which explains their similar minimalist vibes.
What makes Flask great?
- Itās lightweight and unopinionated: you choose what you want to use, nothing is forced on you.
- Itās easy to get started with: great for beginners.
- Itās powerful enough for real-world apps: many big projects started with Flask.
It also has a rich ecosystem of extensions, including:
Flask-Loginfor user authenticationFlask-SQLAlchemyfor working with databasesFlask-Sessionfor session management
And the best part? If you know Python basics (functions, decorators, maybe some classes), youāre good to go.
š§° Getting Started with Flask
Letās create a simple Flask app that says “Hello World” when you open it in the browser.
ā Step 1: Set up your project
First, create a new folder for your Flask app.
Make sure you have:
- Python installed on your system (and added to your PATH)
- A terminal (Command Prompt, PowerShell, Bash⦠pick your flavor)
ā Step 1: Create and activate a virtual environment:
Windows
python -m venv venv
.\venv\Scripts\activate
macOS/Linux
python3 -m venv venv
source venv/bin/activate
ā Step 2: Inside the activated virtual environment, run:
pip install flask
ā Step 3: Write your first Flask app
In main.py, paste this:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Hello, World!"
if __name__ == "__main__":
app.run(debug=True)
Now run the file:
python main.py
Open your browser and go to http://localhost:5000.
Boom. š Youāve just created your first Flask app.
š Where to Learn More
Want to go deeper? Here are some awesome resources that i also use to learn: