A repo to kickstart your Django Project
Backend | Frontend | DevOps | Data | Project Management | Tools |
---|---|---|---|---|---|
Python | HTMX | Docker | PostgreSQL | GitHub | uv |
Django | JavaScript | CI/CD | SQLAlchemy | npm | |
Pytest | CSS | Terraform | pgAdmin | ||
HTML5 | Hetzner | ||||
Change:
- Search and replace
your-url.com;
with your URL. - Search and replace
django_docker_starter
with your project's name. - Change
main.tf
if you are not deploying on Hetzner.
git clone git@github.com:hemroda/django_docker_starter.git
- Install uv
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
- Environment variables
cp .env.sample .env
cp ./django-app/.env.sample ./django-app/.env
- Build the project using Docker
docker-compose up -d --build
==> For Django, go to http://localhost:8080
- Pre-commit
pip install pre-commit
django-app
directory.
uv add name-of-package
uv add name-of-package --dev
- List the migrations
docker-compose exec django-app python manage.py showmigrations
- If your changes are not listed, create a migration file for it
docker-compose exec django-app python manage.py makemigrations
- Run the migrations
docker-compose exec django-app python manage.py migrate --noinput
models
folder. which means you need to add the newly created model to the imports in the_app/models/__init__.py
file.
Example in django-app/apps/app-name
, you just created the Task
model, you would add it this way:
from .project import Project
from .task import Task
__all__ = ["Project", "Task"]
Now re-run the 2 commands above.
- Ensure the default Django tables were created:
See Database section bellow.
docker-compose exec django-app python manage.py shell_plus
mkdir apps/name_of_the_app
docker-compose exec django-app python manage.py startapp name_of_the_app ./apps/name_of_the_app
docker-compose run --rm django-app sh -c "python manage.py createsuperuser"
There few accounts created during the seed process:
-
For admin section:
url: http://localhost:8080/admin
username:
admin
password:
password
-
For non superuser (accounts):
url: http://localhost:8080/login
username:
seconduser
password:
password
These logins are usable in development.
docker-compose exec db psql --username=pguser --dbname=django_docker_starter_db
Go to http://localhost:4000/login
Use the following logins:
- user/email: admin@users.com
- password: adminpassword
When creating the server:
-
General tab:
- name: server
-
Connection tab:
-
Host name/address: db
-
Username: pguser
-
Password: pguserpassword
⚠️ The other fields do not change -
-
Before First deploy:
- Search and replace
your-email@example.co
with your email.
- SSH to the server.
- cd into
django_docker_starter
folder - Pull the changes, run
git pull origin main
- Run the following commands:
docker-compose -f docker-compose-prod.yml up -d --build
If only django-app
was updated, run:
docker-compose -f docker-compose-prod.yml up -d --build django-app
docker-compose exec django-app python manage.py createsuperuser