Skip to content

CEPHAL0/django-boiler-plate

Repository files navigation

Django Boilerplate

This repository serves as a boilerplate for Django projects, providing a structured setup for handling responses, serializers, views, permissions, logging, and more. It is designed to help developers quickly start a Django project with best practices and reusable components.


Features

1. Custom Response Wrappers

  • Centralized success and error response utilities in responses.py.
  • Ensures consistent API responses with fields like status, status_code, message, and data.

2. Custom Exception Handling

  • Global exception handler in exception_handler.py.
  • Logs unhandled exceptions and provides user-friendly error messages.

3. Custom Renderers

4. Dynamic Role and Permission Management

5. Custom User Model

  • Extended AbstractUser model with additional fields like created_at, updated_at, and deleted_at in models.py.

6. Swagger Integration

  • Auto-generated API documentation using drf-yasg.
  • Swagger and ReDoc views available at /swagger and /redoc.

7. Logging

  • Centralized logging configuration in logging.py.
  • Logs are stored in the logs/ directory with support for colored console output.

8. Environment Configuration

  • Environment variables are managed using python-dotenv.
  • Centralized access to environment variables in env_constants.py.

9. Custom Base Model

  • Abstract base model with created_at and updated_at fields in base_model.py.

10. Predefined Management Commands

  • setup_roles: Dynamically create roles and assign permissions.
  • create_users: Generate test users using Faker.

Project Structure

1. Clone the Repository

git clone https://github.com/your-username/django-boiler-plate.git
cd django-boiler-plate

2. Set Up Environment Variables

  • Copy the .env.example file to .env
  • Update the .env file with your environment-specific values

3. Install Dependencies

pip install -r requirements.txt

4. Run Migrations

python manage.py migrate

5. Run the Development Server

python manage.py runserver

6. Access Swagger Documentation


Management Commands

1. Setup Roles

Dynamically creates roles and assigns permissions:

python manage.py setup_roles

2. Create Test Users

Generates 10 test users using Faker:

python manage.py create_users

API Endpoints

User Endpoints

Method Endpoint Description
GET /users/csrf Fetch CSRF token
POST /users/register Register a new user
POST /users/login Log in a user
GET /users/logout Log out a user
GET /users/whoami Fetch current user profile

Dependencies

  • Django: 5.2.4
  • Django REST Framework: 3.16.0
  • drf-yasg: 1.21.10
  • Faker: 37.6.0
  • python-dotenv: 1.1.1
  • PostgreSQL: 16 (via Docker)

Docker Setup

1. Build and Run Containers

docker-compose up --build

2. Access the Application

About

This repository serves as a boilerplate for Django projects. Django + DRF + drf-yasg + Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published