This is a Django blog application that provides a platform to create, update, delete, and interact with blog posts and comments. It also includes a RESTful API using Django REST Framework (DRF) for programmatic CRUD operations.
-
Post Management:
- List all posts.
- View post details with associated comments.
- Create, edit, and delete posts.
-
Comment Management:
- Add, edit, and delete comments for a specific post.
-
Rich Text Editing:
- Includes Django Summernote for rich text post content.
-
Post API:
- List, create, retrieve, update, and delete posts.
- Supports filtering, searching, and ordering.
-
Comment API:
- Extendable for comment management via DRF.
- Includes Swagger and ReDoc for API documentation with drf-yasg.
- Django: Web framework for backend.
- Django REST Framework: For building APIs.
- SQLite: Default database (can be configured for PostgreSQL, MySQL, etc.).
- Django Summernote: Rich text editor for posts.
- drf-yasg: Interactive API documentation.
- Django Filters: For advanced filtering options in APIs.
- Python >= 3.8
- Django >= 4.x
- Install
pip
for Python package management.
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Apply migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
-
Access the application:
- Web app:
http://127.0.0.1:8000/
- Swagger API:
http://127.0.0.1:8000/swagger/
- Web app:
URL Pattern | View (FBVs & CBVs) | Description |
---|---|---|
/posts/ |
post_list (FBV) |
List all posts |
/posts/<int:pk>/ |
post_detail (FBV) |
View post details |
/add_post/ |
creat_post (FBV) |
Add a new post |
/edit_post/<int:pk>/ |
edit_post (FBV) |
Edit an existing post |
/delete_post/<int:pk>/ |
delete_post (FBV) |
Delete a specific post |
/posts/<int:post_pk>/<int:comment_pk>/ |
comment_edit (FBV) |
Edit a comment |
/posts/<int:post_pk>/<int:comment_pk>/delete/ |
comment_delete (FBV) |
Delete a comment |
Method | Endpoint | Description |
---|---|---|
GET | /posts/api/ |
List all posts |
POST | /posts/api/ |
Create a new post |
GET | /posts/api/<int:pk>/ |
Retrieve post details |
PUT | /posts/api/<int:pk>/ |
Update a specific post |
DELETE | /posts/api/<int:pk>/ |
Delete a specific post |
project/
│
├── posts/
│ ├── views.py # Function-based views
│ ├── views2.py # Class-based views
│ ├── api.py # DRF API views
│ ├── models.py # Post and Comment models
│ ├── serializers.py # DRF serializers for APIs
│ ├── urls.py # App-specific URL patterns
│ ├── templates/ # HTML templates for the app
│ └── forms.py # Forms for posts and comments
│
├── manage.py # Django management script
├── settings.py # Project settings
└── urls.py # Project-level URL patterns
The project includes interactive API documentation via Swagger and ReDoc:
- Swagger UI:
/swagger/
- ReDoc UI:
/redoc/
- Raw Schema:
/swagger.json
or/swagger.yaml
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add new feature"
- Push to the branch:
git push origin feature-name
- Submit a pull request.