🎓 School Project – Blogging Service built with Flask (Python) and Postgres, featuring a frontend built with HTML, CSS, and JavaScript served via Flask templates.
📖 Course: UUY-CSC222
🏫 Department: Computer Science
👥 Group: 2
🎓 Series: 022/023
Web-based blogging platform built on a monolithic architecture that allows users to create, edit and publish blog posts.
- Flask backend with Postgres database
- Frontend served from Flask templates with static assets
- API endpoints for post & category creation, deletion and editing
- Python 3.x, Flask
- Postgres database
- HTML, CSS, JavaScript served via Flask
templatesandstaticfolders
git clone https://github.com/Faculty-of-Computing/uuycsc22blogproject.git
cd uuycsc22blogprojectpython3 -m venv venv
source venv/bin/activatepip install -r requirements.txtTo set it up and run on local, get a free PostgreSQL server online. From Supabase for example, or you can just setup PostgreSQL on your PC at once
DB_NAME=databasename
DB_USER=yourusername
DB_PASSWORD=12345678
DB_HOST=localhost
DB_PORT=5432
SECRET_KEY=your_secret_key
python app.pyThe app will be available at:
http://localhost:5000
/ Function: index() Purpose: Show all published (non-draft) posts, with optional search and category filtering. SQL:
Selects post info, author username, category name, and comment count for each post. Filters by draft status, search term, and category if provided. Orders posts by timestamp (newest first). /category/int:category_id Function: category_view(category_id) Purpose: Show all published posts in a specific category. SQL:
Selects posts with matching category, author username, category name, and comment count. Orders by timestamp. /createpost Function: createpost() Purpose: Allow logged-in users to create a new post (with optional image and category). SQL:
Inserts a new post into the post table with title, body, draft status, user, category, and image. /editpost/int:post_id Function: editpost(post_id) Purpose: Allow the post's author to edit an existing post. SQL:
Updates the post's title, body, draft status, category, and image in the post table. /delete_post/int:post_id Function: delete_post(post_id) Purpose: Allow the post's author to delete a post. SQL:
Deletes all comments for the post. Deletes the post itself. /post/int:post_id Function: view_post(post_id) Purpose: Show a single post and its comments. SQL:
Selects post info, author username, and category name. Selects all comments for the post, with commenter username. /post/int:post_id/comment Function: add_comment(post_id) Purpose: Add a comment to a post (must be logged in). SQL:
Inserts a new comment into the comment table with post, user, text, and timestamp. /signup Function: signup() Purpose: Register a new user. SQL:
Inserts a new user into the user table with username, email, and password. /login Function: login() Purpose: Log in a user. SQL:
Selects a user from the user table matching the provided username and password. /logout Function: logout() Purpose: Log out the current user (clear session).
/add-category Function: add_category() Purpose: Add a new category (must be logged in). SQL:
Inserts a new category into the category table. Utility Functions get_db() Purpose: Get a database connection from Flask's g context.
close_connection(exception) Purpose: Close the database connection after request.
init_db() Purpose: Initialize the database using the schema in schema.sql.
login_required(f) Purpose: Decorator to require login for certain endpoints.
load_logged_in_user() Purpose: Load the current user into Flask's g context before each request.
inject_user() Purpose: Make the current user available in Jinja templates.
inject_csrf_token() Purpose: Make the CSRF token available in Jinja templates.
set_csrf_token() Purpose: Set a CSRF token in the session before each request.
get_post_by_id(post_id) Purpose: Utility to fetch a post by ID, including author and category info.
SQL Query Meanings SELECT … FROM post JOIN "user" … LEFT JOIN category … Fetches posts with author and category info.
INSERT INTO post … Adds a new blog post.
UPDATE post SET … WHERE id = … Edits an existing post.
DELETE FROM post WHERE id = … Removes a post.
DELETE FROM comment WHERE post_id = … Removes all comments for a post.
INSERT INTO comment … Adds a new comment.
SELECT * FROM "user" WHERE … Fetches user info for login or session.
INSERT INTO "user" … Registers a new user.
INSERT INTO category … Adds a new category.