How to Build a Web App using Flask and SQLite in Python (original) (raw)

Last Updated : 4 Jun, 2026

A simple data-driven web application can be built using Flask and SQLite by combining form handling, database operations, and dynamic page rendering. The application collects user information, stores it in an SQLite database, and displays the stored records through Flask templates.

Run the following commands to install Flask:

pip install flask

Building an App Using Flask and SQLite

**Prerequisites:

After setting up the virtual environment and flask app, we can start building the application.

File Structure

This is how the file structure of our app will look like after completion.

Build-WEb-app-in-flask-using-sqlite

File structure of Flask app

index.html

The index.html file will contain two buttons, one button to check all the participant's lists (taken from the database). And the other button to create a new entry.

HTML `

Flask and SQLite

Build Web App Using Flask and SQLite

Fill form to get updates
Check participant list

`

join.html

Create join.html file in the templates folder, it will contain a form to collect Name, Email, City, Country, and Phone. Use the POST method to submit the data, then insert it into the database and commit the changes.

HTML `

Flask and SQLite Enter Name:
Enter Email:
Enter City:
Enter Country:
Enter phone num:

`

participants.html

Use table tag and assign the heading using tag. To auto increment, the table row on the new entry, use a For loop jinja template. Inside For loop add and tags.

HTML `

Flask and SQLite {%for participant in data%} {%endfor%}
Name Email City Country Phone Number
{{participant[0]}} {{participant[1]}} {{participant[2]}} {{participant[3]}} {{participant[4]}}

`

app.py

Create a file named app.py to define the Flask application, configure the SQLite database, handle form submissions, store participant details, and retrieve records for display in the web interface.

Python `

from flask import Flask, render_template, request import sqlite3

app = Flask(name)

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

connect = sqlite3.connect('database.db') connect.execute(''' CREATE TABLE IF NOT EXISTS PARTICIPANTS ( name TEXT NOT NULL, email TEXT NOT NULL, city TEXT NOT NULL, country TEXT NOT NULL, phone TEXT NOT NULL ) ''')

@app.route('/join', methods=['GET', 'POST']) def join(): if request.method == 'POST': name = request.form['name'] email = request.form['email'] city = request.form['city'] country = request.form['country'] phone = request.form['phone'] with sqlite3.connect("database.db") as users: cursor = users.cursor() cursor.execute("INSERT INTO PARTICIPANTS
(name,email,city,country,phone) VALUES (?,?,?,?,?)", (name, email, city, country, phone)) users.commit() return render_template( "index.html", message="Registration successful!" ) else: return render_template('join.html')

@app.route('/participants') def participants(): connect = sqlite3.connect('database.db') cursor = connect.cursor() cursor.execute('SELECT * FROM PARTICIPANTS')

data = cursor.fetchall()
connect.close()
return render_template("participants.html", data=data)

if name == 'main': app.run(debug=False)

`

**Output:

How to Build a Web App using Flask and SQLite in Python

Home Page of App

**For route: http://127.0.0.1:5000/join

Here we are adding two new data to the database.

How to Build a Web App using Flask and SQLite in Python

data 1

How to Build a Web App using Flask and SQLite in Python

data 2

For route: http://127.0.0.1:5000/participants

How to Build a Web App using Flask and SQLite in Python

List of Participants

**Explanation: