Steps to Creating a Simple Web App with Flask in Python

8/17/2025

Step-by-step guide to creating a simple web application using Flask in Python with routes, templates, and user input

Go Back

Steps to Creating a Simple Web App with Flask in Python

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.


Step-by-step guide to creating a simple web application using Flask in Python with routes, templates, and user input

Why Use Flask for Web Development?

  • Lightweight – Minimal setup required.

  • Flexible – Gives developers full control.

  • Extensible – Supports plugins and third-party extensions.

  • Beginner-friendly – Easy to learn for Python developers.


Step 1: Install Flask

First, install Flask using pip:

pip install flask

✅ This will install Flask and its dependencies.


Step 2: Create a Project Directory

Make a new folder for your project:

mkdir flask_app
cd flask_app

Inside the folder, create a file named app.py.


Step 3: Write Your First Flask App

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 (/).


Step 4: Run the Flask App

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.


Step 5: Add More Routes

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.


Step 6: Use HTML Templates

Flask uses Jinja2 templates to render HTML files dynamically.

  1. Create a folder named templates in your project directory.

  2. Inside it, create index.html:

<!DOCTYPE html>
<html>
<head>
    <title>Flask App</title>
</head>
<body>
    <h1>Welcome to My Flask App</h1>
</body>
</html>
  1. 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.


Step 7: Handling User Input

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.


Best Practices for Flask Apps

  1. Use virtual environments to manage dependencies.

  2. Organize your project structure (separate routes, templates, static files).

  3. Enable debug mode only during development.

  4. Use environment variables for sensitive data like API keys.

  5. Deploy using production servers (e.g., Gunicorn, Nginx) for real-world apps.


Real-World Applications of Flask

  • 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.


Conclusion

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.


SEO Keywords:

  • 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

Table of content