A batteries-included Django REST Framework template to kickstart your API development with best practices and common configurations out of the box.
- Pre-configured Django REST Framework with Token Authentication
- Environment-based Settings using python-dotenv
- Database Flexibility
- SQLite (default)
- PostgreSQL support built-in
- Enhanced Admin Interface with Django Jazzmin
- API Documentation with drf-yasg (Swagger/OpenAPI)
- CORS Configuration ready for frontend integration
- Project Renaming Utility included
- Security Features pre-configured
- CSRF protection
- Proper security settings
- Environment-based DEBUG mode
- Clone this repository:
git clone https://github.com/leen2233/drf-project-template.git
cd drf-project-template- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root:
SECRET_KEY=your-secret-key
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
CORS_ALLOWED_ORIGINS=http://localhost:3000
CSRF_TRUSTED_ORIGINS=http://localhost:3000
# Database configuration (optional)
DATABASE_PROVIDER=sqlite3 # or postgres
POSTGRES_DB=your_db_name
POSTGRES_USER=your_db_user
POSTGRES_PASSWORD=your_db_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432- Rename the project (optional):
python manage.py rename_project your_project_name- Run migrations:
python manage.py migrate- Create a superuser:
python manage.py createsuperuser- Run the development server:
python manage.py runserverproject/
├── app/ # Main application directory
│ ├── management/ # Custom management commands
│ └── urls.py # Application URLs
├── project/ # Project configuration directory
│ ├── settings.py # Project settings
│ ├── urls.py # Project URL configuration
│ ├── wsgi.py # WSGI configuration
│ └── asgi.py # ASGI configuration
├── .env # Environment variables
├── manage.py # Django management script
└── requirements.txt # Project dependencies
- Django REST Framework - Powerful and flexible toolkit for building Web APIs
- Django Jazzmin - Beautiful admin interface
- drf-yasg - Automated API documentation
- django-cors-headers - Handling CORS in Django
- python-dotenv - Environment variable management
The project supports both SQLite and PostgreSQL out of the box. To use PostgreSQL:
- Set in your
.env:
DATABASE_PROVIDER=postgres
POSTGRES_DB=your_db_name
POSTGRES_USER=your_db_user
POSTGRES_PASSWORD=your_db_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432Configure CORS in your .env:
CORS_ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com
CSRF_TRUSTED_ORIGINS=http://localhost:3000,https://yourdomain.com- Never commit your
.envfile - Change the SECRET_KEY in production
- Set DEBUG=False in production
- Configure proper ALLOWED_HOSTS in production
- Use proper SSL/TLS in production
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
leen2233 - @leenrejepov
Project Link: https://github.com/leen2233/drf-project-template