Are you new to web development with Python? Want to build a simple website or app? Flask is a great place to start! This guide will walk you through everything step by step—no complicated setup, just pure simplicity.
💡 What is Flask?
Flask is a tool that helps you build websites and web apps using Python. It’s:
- Simple to use
- Lightweight
- Great for learning how web apps work
✅ What You Need
Make sure you have the following:
- Python installed (version 3.7 or higher)
- Download Python here
- During installation, make sure to check ✅ “Add Python to PATH”
🔹 Step 1: Install Flask
Let’s install Flask using a command.
- Open the Command Prompt (Windows) or Terminal (Mac/Linux)
- Type this and press Enter:
pip install flask
This will download and install Flask on your computer.
💡 Tip: If
pip
doesn’t work, trypython -m pip install flask
🔹 Step 2: Create Your First Flask App
Now let’s build your first Flask website.
- Open any folder (like
Documents
) and create a new folder calledflask_app
- Open Notepad (or any text editor like VS Code)
- Copy this code and save it as
app.py
inside theflask_app
folder:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, Flask!'
if __name__ == '__main__':
app.run()
🔹 Step 3: Run the App
Now let’s run the app!
- Open Command Prompt (Windows) or Terminal (Mac/Linux)
- Navigate to the folder where your
app.py
is. Example:
cd Desktop\flask_app
(Or wherever you saved the file)
- Run the app:
python app.py
If everything is okay, you’ll see something like this:
* Running on http://127.0.0.1:5000/
- Open your browser and go to http://127.0.0.1:5000/
You’ll see Hello, Flask! 🎉
🧪 Step 4: Try More Routes
Want to add more pages?
Open app.py
and add these lines:
@app.route('/about')
def about():
return 'This is the About page'
@app.route('/hello/<name>')
def greet(name):
return f'Hello, {name}!'
Save the file and restart your app (press Ctrl+C, then run python app.py
again). Now try:
🎯 What’s Next?
You’ve just built your first Flask app! From here, you can:
- Add HTML pages
- Accept form inputs
- Connect to a database
- Build real apps like a blog or a to-do list
📚 Resources to Keep Learning
- Flask Official Website
- Flask Crash Course (YouTube – Traversy Media)
- Build a Website with Flask (FreeCodeCamp)
🙌 Final Words
Flask makes it easy to turn your Python code into a working website. Don’t worry about doing everything perfectly—just keep experimenting and building!