This is a Dockerised Django Project template
- Clone this repo, cd into it, and copy the
.envfile:
git clone https://github.com/user/repo
cd repo
cp .env.example .env-
Edit the
.envfile and review its settings. At a minimum, you'll probably want to uncommentDEBUG=truefor testing -
Start Django
-
To do so using Docker:
docker compose -f docker-compose.dev.yml up -d
-
To do so using a Python
venv:NOTE: These instructions are only tested on macOS and Linux
Perform the initial set-up (do this only once):
# Create a virtual environment python3 -m venv .venv # Activate virtual environment . .venv/bin/activate # Install Python dependencies pip install -r django/requirements.txt # Change to the django dir cd django/ # Run the Docker entrypoint script to set up an initial superuser etc ./docker-entrypoint.sh cd .. deactivate
Start up Django (do this every time):
# Activate virtual environment . .venv/bin/activate # Change to the django dir cd django/ # Start Django ./manage.py runserver
- Log into admin console at http://localhost:8000/admin as
root/root
Now you've got Django up and running, you should be at the point where you can follow the Django documentation to create your first app. The short version of what you need to do from here is:
- Create an app:
If using Docker:
docker compose -f docker-compose.dev.yml exec app ./manage.py startapp myappIf using a virtual environment:
./manage.py startapp myapp-
Edit both
django/myproject/settings.pyanddjango/myproject/urls.py, search formyapp, and uncomment the line as instructed. -
Set up appropriate views in
django/myapp/views.py, and URLs indjango/myapp/urls.py, before browsing to http://localhost:8000/
By default there is no docker-compose.yml, so docker compose up won't work without specifying one of the other files.
docker-compose.dev.yml is designed for use during development. You probably also want to uncomment the DEBUG line in the .env file in this case.
docker-compose.prod.yml is designed for production.
docker-compose.traefik.yml is designed for production when using Traefik as a HTTP proxy
For convenience, any of these files could be copied or symlinked to docker-compose.yml so you don't need to specify the file with docker compose -f file.yml.