Steps to Creating a Simple Web App with Flask in Python
Step-by-step guide to creating a simple web application using Flask in Python with routes, templates, and user input
Flask is a lightweight and flexible Python web framework that allows developers to quickly build web applications. It is popular because of its simplicity, scalability, and ease of integration with other tools. If you are new to web development with Python, Flask is one of the best places to start.
In this article, we’ll walk you through the steps required to create a simple web app with Flask, including installation, setup, and building your first routes.
Lightweight – Minimal setup required.
Flexible – Gives developers full control.
Extensible – Supports plugins and third-party extensions.
Beginner-friendly – Easy to learn for Python developers.
First, install Flask using pip:
pip install flask
✅ This will install Flask and its dependencies.
Make a new folder for your project:
mkdir flask_app
cd flask_app
Inside the folder, create a file named app.py
.
Open 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 creates a basic Flask app with one route (/
).
Run the app with:
python app.py
You will see output showing that the server is running, usually at:
http://127.0.0.1:5000/
Open this link in your browser to see your web app in action.
Flask allows you to add multiple routes for different pages.
@app.route('/about')
def about():
return "This is the About page of the Flask app."
Visiting http://127.0.0.1:5000/about
will now display the About page.
Flask uses Jinja2 templates to render HTML files dynamically.
Create a folder named templates in your project directory.
Inside it, create index.html
:
<!DOCTYPE html>
<html>
<head>
<title>Flask App</title>
</head>
<body>
<h1>Welcome to My Flask App</h1>
</body>
</html>
Update app.py
:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template("index.html")
✅ Now, Flask renders an HTML page instead of plain text.
You can also create forms and handle user input in Flask.
from flask import request
@app.route('/greet', methods=['GET', 'POST'])
def greet():
if request.method == 'POST':
name = request.form['name']
return f"Hello, {name}!"
return "<form method='post'><input name='name'><input type='submit'></form>"
✅ This route accepts user input and displays a personalized greeting.
Use virtual environments to manage dependencies.
Organize your project structure (separate routes, templates, static files).
Enable debug mode only during development.
Use environment variables for sensitive data like API keys.
Deploy using production servers (e.g., Gunicorn, Nginx) for real-world apps.
Websites and Blogs – Build small to medium-scale websites.
APIs – Flask is widely used for REST API development.
Data Dashboards – Integrating Flask with Pandas, Plotly, and Dash.
Prototyping – Quickly test ideas before moving to full-scale frameworks like Django.
Flask makes it easy to build web applications in Python. With just a few lines of code, you can create a fully functional web app. By following the steps outlined above, you can get started with Flask development and expand your skills toward building scalable and production-ready applications.
create a Flask web app in Python
Flask web application tutorial
simple Flask app example
Flask Python step by step
build web app using Flask