A simple blog application built with Flask, SQLAlchemy, and Flask-WTF. Users can register, log in, create posts, comment, and edit or delete posts (admin only). This project demonstrates the use of Flask, database integration, user authentication, and forms.
- Register and log in
- Add comments to posts
- View all posts
- Add new blog posts
- Edit or delete posts
- Display posts with title, subtitle, body, and image
- Comment system
- CKEditor for rich text in posts
- Clone this repository:
git clone https://github.com/yourusername/flask-blog.git
cd flask-blog- Create a virtual environment:
python -m venv .venv
# Linux / Mac
source .venv/bin/activate
# Windows
.venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Add environment variables in a
.envfile:
FLASK_KEY=your-secret-key
DB_URI=sqlite:///posts.db # Optional: defaults to SQLite if not set
Run the application:
python main.py- Open your browser at
http://127.0.0.1:5000/ - Register a user or log in
- Admin user (ID=1) can add, edit, or delete posts
- Uses SQLite by default (
posts.db) - SQLAlchemy handles the database models:
User,BlogPost,Comment
- Keep your SECRET_KEY private
- Admin-only routes are protected by a decorator
- Uses Flask-Bootstrap5 and Flask-CKEditor for styling and rich text