Template repository for a Docker+Django project
- Scalable Django web app with login/registration and initial Bootstrap 4 template
- Nginx for load balancing traffic to the Django web apps when scaled
- PostgreSQL database
- Python 3.10 (optional, development should be done in the provided Docker environment)
- Docker Desktop (or Docker Compose)
You can check this template in action using the URL https://ddt.ron.sh/
- Fork this project.
- Go to settings and convert your fork to a Template Repository, if not yet checked.
- Create a new project and specify a Repository template to use.
- Happy coding!
Note: update the environment variables in env
folder before running the following commands:
cd <project-folder>
docker-compose build
docker-compose up # or "docker-compose up -d" to run in detached mode
Go to http://localhost:8081
If you don't have a DigitalOcean account yet, create one using my referral link.
- Create a Domain and add an
A record
pointing to your Droplet. - Inside your Droplet, create an SSL certificate:
certbot --nginx -d <domain>
- Edit the nginx configuration (usually /etc/nginx/sites-available/default) and update the
location /
block just below the domain created by certbot (look forserver_name <domain>; # managed by Certbot
):
location / {
proxy_pass http://127.0.0.1:8081$request_uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
- Reload nginx:
service nginx reload
To scale up, add --scale web=N parameter. For example:
docker-compose up --scale web=3
poetry run python manage.py makemessages -l <language_code>
# edit and translate locale/<language_code>/LC_MESSAGES/django.po
Use the Makefile
included for running different development tasks:
make install
- installs the packages needed for development.make build
- build application.make start
- start application.make format
- runsautoflake
,isort
andblack
for fixing coding style.make lint
- runsautoflake
,isort
,black
,flake8
andmypy
checks.make test
- run unit tests.make migrations
- generate migration scripts, if applicable.make migrate
- run migrations, if applicable.make superuser
- create superuser.make messages
- update messages.make compilemessages
- compile messages.make dumpdata
- backup data.make loaddata
- load data from backup.