This repository serves as a template for creating a Django REST Framework (DRF) project that is containerized using Docker. It provides a structured starting point for developing Django-based web applications with a RESTful API, allowing for easier setup and deployment.
- Django 3.x and Django REST Framework (DRF) pre-configured
- PostgreSQL database integration
- Docker and Docker Compose configuration for containerization
- Separation of development and production settings
- Automatic database setup and migrations using Django's
manage.py
commands - Ready-to-use Django project structure following best practices
- Simple API endpoint for testing purposes
- Customizable and extensible to fit your project's needs
Before using this template, ensure that you have the following dependencies installed on your system:
- Docker: Install Docker
- Docker Compose: Install Docker Compose
To start a new project using this template, follow these steps:
- Clone this repository to your local machine:
git clone https://github.com/Palwisha-18/django-drf-template.git
- Navigate into the
django_project
directory:
cd django-drf-template
cd django_project
- Set environment variables:
cp .env.example .env
Open the .env
file and set the value of all environment variables.
- Build and run the Docker containers:
docker-compose up -d --build
This command will download the required Docker images, set up the containers, and start the development server.
- Access the Django application:
You can access the Django application running on 127.0.0.1:8000
in your web browser.
- Test the API endpoint:
A sample API endpoint is available at 127.0.0.1:8000/api/app1/home
. You can modify or extend it according to your project's requirements.
- Rename
django_project
folder according to the name of your django project and replace its usage in the project. - Rename
app1
to represent the application name in your django project. Similarly, replace its usage in the project. - You can add more apps under api directory. For each app added, add app name to
INSTALLED_APPS
inconfig/settings/base.py
and add app urls toapi/urls.py
-
Django Settings: The project-specific Django settings are located in the
config/settings/
directory. You can modify these files to adjust the project's configuration based on your needs. -
Database: By default, this template uses PostgreSQL as the database backend. You can update the database settings in the
docker-compose.yml
andconfig/settings/base.py
-
Docker Configuration: The Docker configuration files (
Dockerfile
anddocker-compose.yml
) are included in the root directory. If you need to make changes to the container setup or add additional services, you can modify these files accordingly.
- During development, you can modify the Django code, and the changes will be automatically detected and applied.
- To stop the development server and the associated containers, use the following command:
docker-compose down
To deploy the project to a production environment, you can use Docker Compose or any other preferred deployment method. Ensure that you update the necessary configurations for a production environment, such as using a secure secret key, configuring HTTPS, and setting up any required production database or caching services.
If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
This project template is inspired by the excellent Django and Docker tutorials and best practices available in the Django and Docker communities.