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.
- Centralized success and error response utilities in
responses.py. - Ensures consistent API responses with fields like
status,status_code,message, anddata.
- Global exception handler in
exception_handler.py. - Logs unhandled exceptions and provides user-friendly error messages.
- API responses are wrapped in a consistent structure using
ApiWrapperRenderer.
- Management command to dynamically create roles and assign permissions in
setup_roles.py. - Enum-based permission generation in
application_role_names.py.
- Extended
AbstractUsermodel with additional fields likecreated_at,updated_at, anddeleted_atinmodels.py.
- Auto-generated API documentation using
drf-yasg. - Swagger and ReDoc views available at
/swaggerand/redoc.
- Centralized logging configuration in
logging.py. - Logs are stored in the
logs/directory with support for colored console output.
- Environment variables are managed using
python-dotenv. - Centralized access to environment variables in
env_constants.py.
- Abstract base model with
created_atandupdated_atfields inbase_model.py.
setup_roles: Dynamically create roles and assign permissions.create_users: Generate test users using Faker.
git clone https://github.com/your-username/django-boiler-plate.git
cd django-boiler-plate- Copy the
.env.examplefile to.env - Update the
.envfile with your environment-specific values
pip install -r requirements.txtpython manage.py migratepython manage.py runserver- Swagger UI: http://localhost:8000/swagger
- ReDoc: http://localhost:8000/redoc
Dynamically creates roles and assigns permissions:
python manage.py setup_rolesGenerates 10 test users using Faker:
python manage.py create_users| 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 |
- 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-compose up --build- Web: http://localhost:8000
- Database:
localhost:5432