This project is a learning sandbox for Flask. It includes two equivalent user-management implementations:
app.pyuses SQLAlchemy ORM models.user.pyuses raw SQL queries with SQLAlchemy sessions.
Both versions render the same UI and share the same templates and static assets. The goal is to help an intern set up the project, run it, and complete a set of feature tasks covering Flask, SQLAlchemy ORM, Jinja2, WTForms, Bootstrap modals, SweetAlert, DataTables, and Select2.
app.py- ORM-based Flask app.user.py- Raw SQL-based Flask app.templates/- Jinja2 HTML templates for users, roles, and layouts.static/- CSS/JS assets (Bootstrap, DataTables, Select2, SweetAlert, jQuery).database.sql- Seed schema or starter SQL.
- Clone the repo.
- Create and activate a virtual environment.
- Install dependencies:
flaskflask_sqlalchemypsycopg2-binary
- Create a PostgreSQL database named
adminand update the connection string if needed:postgresql://postgres:aothecode@127.0.0.1/admin
- Apply
database.sqlto your database. - Run one of the apps:
- ORM version:
python app.py - Raw SQL version:
python user.py
- ORM version:
- Set up Bootstrap modals, SweetAlert confirmations, and jQuery where needed.
- Introduce Flask blueprints for modularization.
- Add Flask-WTForms and use Jinja2 for templating.
- Create a Role entity with list/create/update/delete.
- Link Users to Roles (relationship).
- On user creation, allow selecting a Role from the existing list.
- Add pagination for both Users and Roles using DataTables (server-side or lazy load).
- Use Select2 for role selection with lazy loading on the user creation form.
- Split the project into modules:
users/androles/blueprints.- Separate files for models, forms, and routes (views).
- Add edit/update forms (models or WTForms) for both entities.
- Use SweetAlert for delete confirmations.
- Add filter inputs above each list (Users and Roles).
After completing the tasks, the intern should be comfortable with:
- Flask app structure and blueprints
- SQLAlchemy ORM fundamentals
- Jinja2 templating
- Flask-WTForms
- DataTables pagination and filtering
- Select2 lazy loading
- Bootstrap modals
- SweetAlert confirmations
- jQuery integration