Skip to content

sugeng-riyanto/crudpython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask SQLite CRUD Application

A simple Flask web application demonstrating basic CRUD (Create, Read, Update, Delete) operations using SQLite3 as the database backend.

Features

  • View all users in a table
  • Add new users
  • Edit existing user information
  • Delete users
  • Flash messages for user feedback (success/warning)

Requirements

  • Python 3.x
  • Flask
  • SQLite3 (usually included with Python)

Installation

  1. Clone or download this project to your local machine.

  2. Install dependencies:

    pip install Flask
  3. Initialize the database (optional – the app will work without it, but you’ll need a users table):

    Create a file named db_web.db and run the following SQL command to create the users table:

    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()
  4. Run the application:

    python app.py
  5. Open your browser and go to:

    http://127.0.0.1:5000
    

Project Structure

.
├── 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

Routes

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

Security Note

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

License

This project is open-source and available under the MIT License.

About

This repo is basic program how to create, read, update and delete the data using flask-python, html and css.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors