https://github.com/shahidmalik4/fastapi-html
A lightweight blog application built with FastAPI, supporting user authentication, HTML server-side rendering, and full CRUD functionality for blog posts.
https://github.com/shahidmalik4/fastapi-html
blog fastapi html python sqlalchemy
Last synced: 5 days ago
JSON representation
A lightweight blog application built with FastAPI, supporting user authentication, HTML server-side rendering, and full CRUD functionality for blog posts.
- Host: GitHub
- URL: https://github.com/shahidmalik4/fastapi-html
- Owner: shahidmalik4
- Created: 2025-07-18T06:43:00.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-19T11:41:48.000Z (11 months ago)
- Last Synced: 2025-07-19T16:15:39.818Z (11 months ago)
- Topics: blog, fastapi, html, python, sqlalchemy
- Language: Python
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ FastAPI Blog App with Server-Side HTML Rendering
[](https://www.python.org/)
[](https://fastapi.tiangolo.com/)
[](./LICENSE)
[](#)
A full-featured blog application built with **FastAPI**, **Jinja2**, and **SQLAlchemy**. Supports server-side HTML rendering, user authentication, flash messaging, and full CRUD functionality โ all with clean modular code and session-based route protection.
---
## ๐ Features
- ๐ User registration, login, and logout
- โก Session-based authentication using secure cookies
- ๐ฌ Flash messages for user feedback
- ๐ Create, Read, Update, Delete (CRUD) blog posts
- ๐ Slug generation for posts
- ๐งฐ FastAPI + Jinja2 HTML templating
- ๐งฑ SQLite database (easy to swap out)
- ๐ก๏ธ Protected routes (dashboard, create post, etc.)
- ๐๏ธ Clean, modular architecture (auth, crud, schemas, models)
- ๐ Deployable on **Render**, **Heroku**, or **any ASGI server**
---
## ๐งฐ Tech Stack
- **Framework**: [FastAPI](https://fastapi.tiangolo.com/)
- **ORM**: SQLAlchemy
- **Templates**: Jinja2
- **Schema Validation**: Pydantic
- **Database**: SQLite (can be upgraded to PostgreSQL/MySQL)
- **Web Server**: Uvicorn
---
## ๐ Project Structure
```
fastapi-html/
โโโ app/
โ โโโ auth.py # Auth routes (register, login, logout)
โ โโโ crud.py # Post/user CRUD logic
โ โโโ database.py # SQLAlchemy DB connection
โ โโโ deps.py # Dependency overrides and helpers
โ โโโ main.py # App entry point
โ โโโ models.py # SQLAlchemy models
โ โโโ schemas.py # Pydantic schemas
โ โโโ templates/ # HTML templates
โ โโโ utils.py # Flash messaging & helpers
โโโ blog_app.db # SQLite DB file
โโโ requirements.txt # Python dependencies
โโโ render.yml # Render deployment config
โโโ README.md # You're reading it!
```
---
## ๐ฆ Installation
```bash
# Clone the repository
git clone https://github.com/shahidmalik4/fastapi-html.git
cd fastapi-html
# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the server
uvicorn app.main:app --reload
```
---
## ๐ Auth Flow
- `/register`: Register new user
- `/login`: Login page (sets session)
- `/logout`: Logout and clear session
- Routes like `/dashboard` and `/create-post` are protected and require login
---
## ๐งโ๐ป CRUD Endpoints
| Route | Method | Auth Required | Description |
|-------------------|--------|---------------|--------------------------|
| `/register` | GET/POST | โ | Register a new user |
| `/login` | GET/POST | โ | Login with credentials |
| `/logout` | GET | โ
| Logout user |
| `/dashboard` | GET | โ
| View user dashboard |
| `/create-post` | GET/POST | โ
| Create a new post |
| `/edit-post/{id}` | GET/POST | โ
| Edit an existing post |
| `/delete-post/{id}`| GET | โ
| Delete a post |
| `/post/{slug}` | GET | โ
| View a single post |
---
## ๐งพ Models
```python
๐ง User (SQLAlchemy)
๐ Post (SQLAlchemy)
```
---
## ๐ฆ Pydantic Schemas
```python
class UserCreate(BaseModel):
class UserOut(BaseModel):
class PostBase(BaseModel):
class PostCreate(PostBase):
class PostOut(PostBase):
```
---
## ๐ค Deployment (Render Example)
`render.yml` already included for Render deployment.
> You can also deploy using Docker, Heroku, or any ASGI-compatible cloud.
---