An open API service indexing awesome lists of open source software.

https://github.com/arnobt78/blog--pyflask

BlogWebApp is a Python Flask blog application where users may authenticate, sign-in, log-in, log-out and post content. Other users can like or comment on the article, or the user can delete the posts and comments.
https://github.com/arnobt78/blog--pyflask

bootstrap css flask flask-api flask-application flask-backend flask-login flask-sqlalchemy font-awesome hmtl javascript python

Last synced: 7 months ago
JSON representation

BlogWebApp is a Python Flask blog application where users may authenticate, sign-in, log-in, log-out and post content. Other users can like or comment on the article, or the user can delete the posts and comments.

Awesome Lists containing this project

README

          

# Blog Application - PyFlask

![Screenshot 2024-08-25 at 05 30 31](https://github.com/user-attachments/assets/44be937b-89db-46f2-af65-e34bdf01d83f) ![Screenshot 2024-08-25 at 05 30 49](https://github.com/user-attachments/assets/5e6e93ff-65f7-41a3-b71b-e92bd1eb9315) ![Screenshot 2024-08-25 at 05 33 14](https://github.com/user-attachments/assets/e86b08b2-f436-4e41-8bfb-4c4ff64d4d9b) ![Screenshot 2024-08-25 at 05 32 39](https://github.com/user-attachments/assets/fd782ac8-c605-4b01-8a57-5f5b24b52855) ![Screenshot 2024-08-25 at 05 33 52](https://github.com/user-attachments/assets/c74de127-061e-41d9-8454-c45ff9fe02d6)

---

## Project Summary

**Blog--PyFlask** is a beginner-friendly, full-stack blog web application built using Python's Flask web framework. The project demonstrates all core concepts of web development: routing, database modeling, authentication, CRUD (Create, Read, Update, Delete) operations, templates, and front-end integration with Bootstrap and Fontawesome. Designed for both learning and practical use, it allows users to register, log in, create blog posts, comment, like, and manage their content—all with a responsive user interface and secure access controls.

Whether you're new to Flask or web development in general, this project is a fantastic starting point for learning how modern web apps are structured and function.

---

## Table of Contents

1. [Project Summary](#project-summary)
2. [Features](#features)
3. [Technology Stack](#technology-stack)
4. [Project Structure](#project-structure)
5. [Installation & Getting Started](#installation--getting-started)
6. [Application Walkthrough](#application-walkthrough)
7. [Core Components & APIs](#core-components--apis)
8. [Examples: Usage & Code](#examples-usage--code)
9. [Customization & Further Development](#customization--further-development)
10. [Keywords](#keywords)
11. [Contributing](#contributing)
12. [License](#license)
13. [Conclusion](#conclusion)

---

## Features

- User registration and authentication (login/logout)
- Create, edit, and delete blog posts
- Comment on and like blog posts
- Delete comments (by post author or comment author)
- Responsive UI with Bootstrap and Fontawesome
- Basic access control (users can only delete/edit their own posts/comments)
- Error handling and user feedback messages

---

## Technology Stack

- **Backend:** Python, Flask
- **Frontend:** HTML, CSS, Bootstrap, Fontawesome
- **Database:** SQLite (default, easily configurable for others)
- **Templating:** Jinja2 (Flask's default)
- **Others:** Flask extensions for sessions, forms, database, etc.

---

## Project Structure

```
Blog--PyFlask/

├── app.py # Main Flask application entry point
├── requirements.txt # Python dependencies
├── README.md # Project documentation (you are here)
├── website/ # Main application package
│ ├── __init__.py # App factory & setup
│ ├── models.py # Database models (User, Post, Comment)
│ ├── routes.py # Routes (views/controllers)
│ ├── static/ # Static files (CSS, JS, images)
│ └── templates/ # HTML templates (Jinja2)
├── instance/ # Instance folder (configurations, dev db)
└── __pycache__/ # Python cache files
```
> Note: Some files/folders may be omitted for brevity.

---

## Installation & Getting Started

### 1. Clone the Repository

```sh
git clone https://github.com/arnobt78/Blog--PyFlask.git
cd Blog--PyFlask
```

### 2. Create and Activate a Virtual Environment

```sh
python -m venv .venv
# On Unix/macOS
source .venv/bin/activate
# On Windows
.venv\Scripts\activate
```

### 3. Install Dependencies

```sh
pip install -r requirements.txt
```

### 4. Run the Application

```sh
python app.py
```

By default, the app will be available at **http://127.0.0.1:5000**

---

## Application Walkthrough

1. **Register** a new account or **login** with existing credentials.
2. Once logged in, you can:
- Create a new blog post.
- View posts by all users.
- Like posts and add comments.
- Delete your own posts or comments.
3. Use the navigation bar to explore, create, and manage content.

Refer to the screenshots at the top for UI reference and expected features.

---

## Core Components & APIs

### app.py
- Entry point for the Flask application.
- Calls the app factory in `website/__init__.py`.

### website/__init__.py
- Configures and creates the Flask app instance.
- Sets up database, blueprints, and configuration.

### website/models.py
- Defines database models: `User`, `Post`, `Comment`.
- Example: User model stores username, email, password hash.

### website/routes.py
- Handles all routing (URLs):
- `/register`: Registration logic
- `/login`: Login logic
- `/logout`: Logout endpoint
- `/create-post`: Create new blog posts (auth required)
- `/post/`: View a single post and comments
- `/edit-post/`: Edit owned post
- `/delete-post/`: Delete owned post
- `/like-post/`: Like a post
- More...

### website/templates/
- All HTML templates, using Jinja2 for dynamic content.
- Inherits from a base layout for DRY code.

### website/static/
- Custom CSS, JS, and image files.
- Uses Bootstrap and Fontawesome for styling.

---

## Examples: Usage & Code

### Registering a User

```python
@app.route('/register', methods=['GET', 'POST'])
def register():
# Handles registration logic
```

### Creating a Post

```python
@app.route('/create-post', methods=['GET', 'POST'])
@login_required
def create_post():
# Handles new post creation
```

### Jinja2 Template Example

```html

{% block title %}Blog--PyFlask{% endblock %}

{% block content %}{% endblock %}

```

### Database Model Example

```python
# website/models.py
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(150), unique=True, nullable=False)
email = db.Column(db.String(150), unique=True, nullable=False)
password = db.Column(db.String(150), nullable=False)
posts = db.relationship('Post', backref='author', lazy=True)
```

---

## Customization & Further Development

- Switch to a different database (e.g., PostgreSQL) by updating config in `website/__init__.py`.
- Extend models for tags, categories, or user profiles.
- Implement user roles (admin/editor).
- Add more advanced front-end features or custom styles.
- Deploy to production with Gunicorn, Nginx, and a production database.

---

## Keywords

Python, Flask, Web Application, Blog, CRUD, Authentication, Bootstrap, HTML, CSS, Fontawesome, Jinja2, SQLite

---

## Contributing

Pull requests and feedback are welcome! For significant changes, please open an issue first to discuss what you would like to change.

---

## License

This project is for educational/demo purposes. For commercial or production use, review and update as needed.

---

## Conclusion

**Blog--PyFlask** is a practical, approachable example of a modern web application built with Flask. It covers all essential aspects of web development, from user authentication to front-end design, and is an ideal learning resource for students and developers new to Flask. Clone, run, and start hacking on your own blog today!

---

**Happy Coding!** 🚀

Thank you for exploring and learning with Blog--PyFlask!