Are you new to web development and want to build your first web application with Python? If yes, then Flask is the perfect place to start! 🎉
Flask is a lightweight and flexible web framework written in Python. Unlike bigger frameworks like Django, Flask keeps things simple and gives you the freedom to build applications your way. In this guide, we’ll walk step by step through setting up Flask and creating your very first web app—even if you’ve never worked with web frameworks before.
🔹 What is Flask?
Flask is a micro web framework in Python. “Micro” means it comes with only the essentials: routing, templating, and server handling. You can add extra features (like database, authentication, etc.) later using extensions.
👉 Think of Flask as a blank canvas—you add the colors (features) you want.
🔹 Installing Flask
Before we start, make sure you have Python 3.x installed.
Create a new project folder, e.g. flask-beginner
Open terminal (or command prompt) in that folder
Install Flask with pip:
pip install flask
Done! ✅
🔹 Your First Flask App
Let’s create a simple “Hello, Flask!” app.
👉 Create a file called app.py and add this code:
from flask import Flask
app = Flask(name)
@app.route("/")
def home():
return "Hello, Flask!"
if name == "main":
app.run(debug=True)
Now run it:
python app.py
You’ll see something like:
Running on http://127.0.0.1:5000/
Open that link in your browser. You should see:
Hello, Flask! 🎉
🔹 Adding Routes
A route is like an address in your app. Let’s add an “About” page.
@app.route("/about")
def about():
return "This is the About Page"
Now visit http://127.0.0.1:5000/about and you’ll see your new page.
🔹 Using HTML Templates
Instead of writing HTML in Python, Flask uses Jinja2 templates.
Create a folder called templates in your project.
Inside it, create a file home.html:
<!DOCTYPE html>
Flask Beginner App
Welcome to Flask!
This page is powered by Flask templates.
Update app.py:
from flask import render_template
@app.route("/")
def home():
return render_template("home.html")
Now refresh your browser. You’ll see your custom HTML 🎨
🔹 Handling Forms
Let’s build a simple form where the user enters their name.
Create a new file inside templates → form.html:
<!DOCTYPE html>
Flask Form
Submit
Update app.py:
from flask import request
@app.route("/form")
def form():
return render_template("form.html")
@app.route("/submit", methods=["POST"])
def submit():
name = request.form["name"]
return f"Hello, {name}!"
👉 Visit http://127.0.0.1:5000/form, type your name, and see Flask greet you.
🔹 What’s Next?
Congratulations 🎉 You’ve just created your first Flask app!
Here are some ideas to continue:
Add more pages with routes and templates
Connect a database (SQLite, MySQL, PostgreSQL)
Learn about Flask extensions (Flask-Login, Flask-WTF, Flask-Mail, etc.)
Deploy your app to Heroku, PythonAnywhere, or Google Cloud
🔹 Final Thoughts
Flask is simple yet powerful. Whether you want to build a small portfolio site, an API backend, or even a full web app, Flask has you covered.
👉 If you found this helpful, share it with friends who are starting out in Python.
👉 Drop your questions in the comments—I’d love to help.
Happy coding 💻✨
Suggested Tags:
python #flask #webdev #beginners #tutorial
Suggestions:
write me on
e-mail:- aniketvaidya@gmail.com
Top comments (0)