We often think big changes require big efforts. But in reality, the smallest habits can have the most profound impact on our lives. Whether it's reading just one page a day, doing five minutes of exercise, or practicing mindfulness for a moment, these tiny actions add up over time.
Small habits are easier to stick with, and they gradually shape our identity. Want to be a reader? Start with a single paragraph. Want to be healthier? Begin with a daily stretch. The key is consistency, not intensity.
So, instead of waiting for the "perfect time" to make a big change, start small today. Your future self will thank you!
If you're a Python developer looking to build web applications quickly and efficiently, Flask is a name you’ve probably heard — and for good reason. It's lightweight, flexible, and perfect for getting projects off the ground with minimal boilerplate. In this post, we’ll take a beginner-friendly look at Flask: what it is, why it’s popular, and how to create your first simple app.
🔍 What Is Flask?
Flask is a micro web framework written in Python. It was created by Armin Ronacher and released in 2010. Despite being "micro", Flask is powerful enough to build robust web applications and APIs. It doesn’t come with a lot of built-in features like Django does — instead, it gives you the tools to pick and choose what you need.
Key Features:
Lightweight and modular
Built-in development server and debugger
RESTful request handling
Templating with Jinja2
Flexible routing
Easily extendable with plugins
🛠️ Installing Flask
Before you begin, make sure you have Python installed. Then, create a virtual environment and install Flask:
bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install Flask
👨💻 Your First Flask App
Create a file called app.py and add the following code:
python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)
How it works:
Flask(__name__): Initializes the app.
@app.route("/"): Sets the route for the home page.
debug=True: Enables the debugger and auto-reloader during development.
Run the app:
bash
python app.py
Open a browser and go to http://127.0.0.1:5000 — you should see "Hello, Flask!"
🧠 Templates and HTML
You can return dynamic HTML using Jinja2 templates. First, create a templates folder and add a file called index.html:
html
<!-- templates/index.html -->
<!DOCTYPE html>
<html>
<head><title>Flask App</title></head>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
Then update app.py:
python
from flask import render_template
@app.route("/hello/<name>")
def hello(name):
return render_template("index.html", name=name)
Visit http://127.0.0.1:5000/hello/World and see how Flask dynamically renders the template.
📦 Building On Top of Flask
With Flask, you can add:
Forms with Flask-WTF
Databases using SQLAlchemy
Authentication via extensions like Flask-Login
APIs using Flask-RESTful
Its flexibility makes it ideal for everything from quick prototypes to full-featured applications.
🎯 Final Thoughts
Flask is a joy to work with because it lets you start simple and scale up when needed. If you’re just beginning your journey into web development with Python, Flask is the perfect place to start.