A simple Flask web application demonstrating basic CRUD (Create, Read, Update, Delete) operations using SQLite3 as the database backend.
- View all users in a table
- Add new users
- Edit existing user information
- Delete users
- Flash messages for user feedback (success/warning)
- Python 3.x
- Flask
- SQLite3 (usually included with Python)
-
Clone or download this project to your local machine.
-
Install dependencies:
pip install Flask
-
Initialize the database (optional – the app will work without it, but you’ll need a
userstable):Create a file named
db_web.dband run the following SQL command to create theuserstable:CREATE TABLE users ( UID INTEGER PRIMARY KEY AUTOINCREMENT, UNAME TEXT NOT NULL, CONTACT TEXT NOT NULL );
Alternatively, you can use a Python script to set up the database:
import sqlite3 conn = sqlite3.connect('db_web.db') conn.execute('''CREATE TABLE users ( UID INTEGER PRIMARY KEY AUTOINCREMENT, UNAME TEXT NOT NULL, CONTACT TEXT NOT NULL);''') conn.close()
-
Run the application:
python app.py
-
Open your browser and go to:
http://127.0.0.1:5000
.
├── app.py # Main Flask application
├── db_web.db # SQLite database (created after first use)
├── templates/
│ ├── index.html # Homepage listing all users
│ ├── add_user.html # Form to add a new user
│ └── edit_user.html # Form to edit an existing user
└── README.md
| Route | Method | Description |
|---|---|---|
/ or /index |
GET | Display all users |
/add_user |
GET | Show form to add a new user |
/add_user |
POST | Insert new user into database |
/edit_user/<uid> |
GET | Show form to edit user |
/edit_user/<uid> |
POST | Update user in database |
/delete_user/<uid> |
GET | Delete user from database |
- This is a demo application for learning purposes.
- It does not include input validation, CSRF protection, or SQL injection safeguards beyond parameterized queries.
- Do not use in production without proper security enhancements.
This project is open-source and available under the MIT License.