This is a boilerplate project for Django applications. It includes Python, Django, PostgreSQL, Docker, Celery, and Redis.
- Django Boilerplate Project
- Build the Stack On Local and Production Development Using Docker and Docker Compose.
Make sure to have the following on your host:
- Python
- Django
- Postgres
- Celery
- Redis
-
Clone the repository: Clone this repository to your local machine.
git clone https://github.com/abdurrahimcs50/Django-Boilerplate-Project.git
-
Set up a virtual environment: It’s a good practice to create a virtual environment for your project to isolate your project’s dependencies.
# Create a virtualenv: python -m venv venv # Activate the virtualenv you have just created: source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install development requirements: Install the project dependencies from the requirements.txt file.
cd Django-Boilerplate-Project pip install -r requirements.txt
-
Set up environment variables: Copy the .env.example file to a new file called .env, and fill in your actual values.
cp .env.example .env # Example .env SECRET_KEY=changeme ALLOWED_HOSTS=localhost 127.0.0.1 DEBUG=1 CSRF_TRUSTED_ORIGINS=https://*.example.com https://*.192.162.0.0.1 ENGINE=django.db.backends.postgresql POSTGRES_DB=changeme POSTGRES_PASSWORD=changeme POSTGRES_USER=changeme POSTGRES_HOST=changeme POSTGRES_PORT=changeme CELERY_BROKER_URL=redis://redis:6379/0
-
Run migrations: Django uses a database-abstraction API that lets you create, retrieve, update, and delete records.
python manage.py makemigrations python manage.py migrate
-
Start the server: You can start the server using the Django’s built-in server for development.
python manage.py runserver
Now, you can visit http://localhost:8000 in your web browser to see your application.
-
Build the Docker images:
docker-compose -f local_dev.yml build
For production:
docker-compose -f production.yml build
-
Run the Docker containers:
docker-compose -f local_dev.yml up # For detached (background) mode, use: docker-compose -f local_dev.yml up -d
For production:
docker-compose -f production.yml up # For detached (background) mode, use: docker-compose -f production.yml up -d
Visit http://localhost:8000 in your web browser for local development or http://localhost or http://127.0.0.1 for production.
-
- In the context of executing commands, the term
web
refers to the target service. Please be aware that usingdocker exec
is not suitable for running management commands in this scenario.
- In the context of executing commands, the term
# Use the following commands to manage your Django application within the Docker container:
# For local development:
docker-compose -f local_dev.yml run --rm web python manage.py makemigrations
docker-compose -f local_dev.yml run --rm web python manage.py migrate
docker-compose -f local_dev.yml run --rm web python manage.py collectstatic
docker-compose -f local_dev.yml run --rm web python manage.py createsuperuser
docker-compose -f local_dev.yml run --rm web python manage.py startapp app_name
docker-compose -f local_dev.yml run --rm web python manage.py shell
# For production:
docker-compose -f production.yml run --rm web python manage.py makemigrations
docker-compose -f production.yml run --rm web python manage.py migrate
docker-compose -f production.yml run --rm web python manage.py collectstatic
docker-compose -f production.yml run --rm web python manage.py createsuperuser
docker-compose -f production.yml run --rm web python manage.py startapp app_name
docker-compose -f production.yml run --rm web python manage.py shell
## Running Tests
To run the tests for your Django application, you can use the following command within the Docker container:
### For local development:
docker-compose -f local_dev.yml run --rm web python manage.py test
### For production:
docker-compose -f production.yml run --rm web python manage.py test
This command will execute all the tests in your project, providing feedback on the success or failure of each test case.
Note: It's recommended to write tests for your Django application to ensure its stability and reliability. You can create test files in the tests
directory of your Django app or follow Django's testing documentation for more information: Django Testing Documentation.
This project is licensed under the MIT License.
👏 Contributions are welcome! Whether you're reporting bugs, suggesting enhancements, or contributing code, your efforts are appreciated.
-
Reporting Bugs: If you encounter issues or unexpected behavior, please create a new issue. Be sure to provide detailed information about the problem and steps to reproduce it.
-
Suggesting Enhancements: Have an idea for improvement? Feel free to suggest it by creating an issue and describing your enhancement.
-
Code Contributions: Want to contribute code? Check the existing issues and pull requests to avoid duplication. Make your changes, test them locally, and submit a pull request.
-
Writing Documentation: If you find something that needs better documentation or want to contribute to our docs, that's fantastic! Clear documentation helps everyone understand and use the project effectively.
-
Providing Feedback: Share your experiences, suggestions, or concerns. Your feedback helps us make the project better.
-
Sharing the Project: If you find this project useful, consider sharing it with others. Spread the word on social media, tech communities, or among your colleagues. The more, the merrier.
Special thanks to abdurrahimcs50 for creating this incredible Django Boilerplate Template and simplifying the development process.
For inquiries, please contact admin@rahim.com.bd or visit https://www.rahim.com.bd.