Go to file
Matt Cengia 8fd27296f4
Merge pull request #12 from mattcen/dependabot/pip/django/gunicorn-22.0.0
Bump gunicorn from 20.1.0 to 22.0.0 in /django
2024-04-17 12:52:30 +10:00
.devcontainer Update dev container 2024-03-14 10:20:19 +11:00
.github Add pre-commit github action 2024-03-09 22:57:13 +11:00
.vscode Code reformatting 2024-03-27 21:15:22 +11:00
db Add prelim support for running outside Docker using SQLite and venv 2022-12-09 14:54:44 +11:00
django Merge pull request #12 from mattcen/dependabot/pip/django/gunicorn-22.0.0 2024-04-17 12:52:30 +10:00
nginx More Docker image pinning 2023-06-05 12:55:22 -07:00
.dockerignore Ignore mypy cache 2024-03-01 22:45:16 +11:00
.drone.yml Revert "Switch to woodpecker" 2023-07-06 10:34:05 +10:00
.env.example Fix typo in .env.example 2024-03-27 18:28:39 +11:00
.gitattributes fixup! Ignore diffs for generated files 2024-04-05 14:40:20 +11:00
.gitignore Ignore mypy cache 2024-03-01 22:45:16 +11:00
.pre-commit-config.yaml Add djlint to pre-commit 2024-03-08 10:32:08 +11:00
LICENSE Add MIT license 2021-06-07 23:25:16 +10:00
README.md Add instructions for setting up initial app and URL routes 2023-06-08 22:38:28 -07:00
docker-compose.dev.yml More Docker image pinning 2023-06-05 12:55:22 -07:00
docker-compose.prod.yml More Docker image pinning 2023-06-05 12:55:22 -07:00
docker-compose.traefik.yml More Docker image pinning 2023-06-05 12:55:22 -07:00

README.md

Dockerised Django

This is a Dockerised Django Project template

Getting started

  1. Clone this repo, cd into it, and copy the .env file:
git clone https://github.com/user/repo
cd repo
cp .env.example .env
  1. Edit the .env file and review its settings. At a minimum, you'll probably want to uncomment DEBUG=true for testing

  2. Start Django

  • To do so using Docker:

    docker-compose up -f docker-compose.dev.yml -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
    
  1. Log into admin console at http://localhost:8000/admin as root/root

Creating your first app

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:

  1. Create an app:

If using Docker:

docker-compose exec app ./manage.py startapp myapp

If using a virtual environment:

./manage.py startapp myapp
  1. Edit both django/myproject/settings.py and django/myproject/urls.py, search for myapp, and uncomment the line as instructed.

  2. Set up appropriate views in django/myapp/views.py, and URLs in django/myapp/urls.py, before browsing to http://localhost:8000/

Notes

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.