08 – Real-World Python Projects – Flask Web App

🎯 Project Objective

To build a web application using Flask, Python’s lightweight web framework. This project demonstrates:

  • Web development with Python
  • Routing and handling HTTP requests
  • Rendering HTML templates
  • Connecting backend logic with frontend UI

Project: Flask Web App

Project Description

A simple Flask Web App allows users to interact via a browser. Example features:

  • Display a homepage
  • Submit a form and display results
  • Render dynamic content
  • Connect with databases for persistent data

Use Cases:

  • Personal portfolio website
  • Feedback or contact form
  • To-do list or small CRUD applications
  • Mini dashboards

Python Example Code – Basic Flask App

1. Install Flask

pip install Flask

2. Project Structure

flask_app/
β”œβ”€β”€ app.py
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ index.html
β”‚   └── result.html

3. app.py

from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/')
def home():
    return render_template("index.html")

@app.route('/submit', methods=['POST'])
def submit():
    name = request.form.get('name')
    email = request.form.get('email')
    return render_template("result.html", name=name, email=email)

if __name__ == '__main__':
    app.run(debug=True)

4. templates/index.html

<!DOCTYPE html>
<html>
<head>
    <title>Flask Web App</title>
</head>
<body>
    <h1>Welcome to Flask Web App</h1>
    <form action="/submit" method="post">
        Name: <input type="text" name="name" required><br><br>
        Email: <input type="email" name="email" required><br><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

5. templates/result.html

<!DOCTYPE html>
<html>
<head>
    <title>Submission Result</title>
</head>
<body>
    <h1>Thank You!</h1>
    <p>Name: {{ name }}</p>
    <p>Email: {{ email }}</p>
    <a href="/">Go Back</a>
</body>
</html>

βœ… Output:

  • Homepage with a form
  • Submission redirects to a result page displaying user input

    βœ… Key Features

    • Web routing using Flask decorators (@app.route)
    • Handle GET and POST requests
    • Render dynamic HTML templates
    • Debug mode for development
    • Modular and scalable architecture


    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *