If you’re looking to get started with Python web development in 2025, Flask is one of the best frameworks to begin with. It’s lightweight, beginner-friendly, and perfect for building small to medium-sized web apps. In this easy tutorial, you’ll learn how to build and run your first Flask web application — even if you’re new to backend development.
Create a Python Web App with Flask
Why Use Flask?
Flask is a micro web framework written in Python. It gives you just the tools you need to get a web app up and running without forcing you into a complex structure. You can add only what you need and scale up as your app grows.
Key benefits of Flask:
- Simple and flexible
- Built-in development server
- Supports templates and routing
- Great for APIs and small web apps
- Strong community and documentation
Step 1: Set Up Your Environment
First, make sure you have Python installed. You can check this by running:
python --version
Then, create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use venv\Scripts\activate
Install Flask using pip:
pip install Flask
Step 2: Create Your Flask App
Create a new file called app.py
and add the following code:
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask! Welcome to your first web app.' if __name__ == '__main__': app.run(debug=True)
This is a minimal Flask app. It sets up a single route (/
) that returns a plain text message.
Step 3: Run the Web App
In your terminal, run the following command:
python app.py
You’ll see output showing that the development server is running, usually at http://127.0.0.1:5000
. Visit that address in your browser, and you should see your message: “Hello, Flask! Welcome to your first web app.”
Step 4: Add an HTML Template
Let’s make the app a bit more interactive. Create a folder named templates
and inside it create a file called index.html
:
<!DOCTYPE html> <html> <head> <title>My Flask Web App</title> </head> <body> <h1>Welcome to My Flask App</h1> <p>This is a dynamic page rendered with Flask and HTML.</p> </body> </html>
Now update your app.py
file:
from flask import Flask, render_template app = Flask(__name__) @app.route('/') def home(): return render_template('index.html')
When you refresh the page, you’ll now see the HTML version rendered from your templates
folder.
Step 5: Add Another Route
You can easily add multiple pages. Try this:
@app.route('/about') def about(): return '<h2>About Page</h2><p>This is a simple Flask application tutorial.</p>'
Now if you go to http://127.0.0.1:5000/about
, you’ll see your About page.
Step 6: Deploy the App (Optional)
Once your app is ready, you can deploy it using platforms like:
- Render (free tier for small apps)
- Heroku (simple Git-based deployment)
- PythonAnywhere (great for beginners)
- Vercel or Netlify (for frontend, connect via API backend)
You’ll just need to add a requirements.txt
file and possibly a Procfile
, depending on your deployment method.
Final Thoughts
Building a web app with Flask is a great way to learn how backend development works. It gives you complete control over your app’s logic, routes, and database integration — while staying easy enough for beginners. Once you’ve mastered the basics, you can add user authentication, connect a database like SQLite or PostgreSQL, and build REST APIs.