| core | ||
| docker | ||
| static | ||
| static_src/css | ||
| {{project_name}} | ||
| .env.example | ||
| .gitignore | ||
| copier.yml | ||
| manage.py | ||
| package.json | ||
| Procfile | ||
| pyproject.toml.jinja | ||
| README.md | ||
| {{_copier_conf.answers_file}}.jinja | ||
Basic Django Template
Quick Start
This template creates a project that is managed using uv so if you don't already have it installed you should do so.
-
Install copier:
uv tool install copier -
Scaffold your project:
copier copy gh:burnsmcd/cor-django-template /path/to/new/project
The above will create a new directory (/path/to/new/project) with your new Django project.
Be sure to update the README.md file, removing everything above the title "Actual Project Name", update that title, and add the path to the git repo.
What's Included
The generated application only contains the basics needed for most Django projects that render the site using Django's template system.
It also assumes the database used in the deployment environments will be PostgreSQL.
Custom User Model
A custom user model and custom user manager is included that removes the username and replaces it with email. Much of the code for this was liberated from this article and a bit from this video and this related repo. Basic updates to forms.py and admin.py are also included.
Initial Project Setup
The first time you run through the installation steps you'll need to run git init before you start and then uv run manage.py makemigrations before
running uv run manage.py migrate in order to create the initial migration
files.
Actual Project Name
Installation
- Install uv.
git clone <path-to-git-repo>cd <path-to-git-repo>uv venvsource .venv/bin/activateuv syncuv run pre-commit installcp .env.example .envexport DJANGO_SETTINGS_MODULE=core.settings.localuv run manage.py makemigrationsuv run manage.py migrateuv run manage.py createsuperuseruv run manage.py collectstaticnpm installuv run manage.py dev
Unit Tests
Running uv run pytest will run all of the tests in your Django app named
test.py, tests.py, test**.py, and tests**.py (see pyproject.toml for details).
To Use PostgreSQL
- Install Docker.
- Edit .env and uncomment the database configuration lines as documented in the file.
uv run manage.py start_db
To stop the database server run uv run manage.py stop_db. You can specify the
local port the contaner is listening on by using the "--port" option, for
example uv run manage.py start_db --port 9876 (make sure to update you .env
file with the new port number). This can be helpful if you're working on
multiple projects, each with their own PostgreSQL server.
To Use Redis
- Install Docker.
- Edit .env and uncomment the database configuration lines as documented in the file.
uv run manage.py start_redis
To stop the Redis server run uv run manage.py stop_redis. You can specify the
local port the contaner is listening on by using the "--port" option, for
example uv run manage.py start_redis --port 9876 (make sure to update you .env
file with the new port number). This can be helpful if you're working on
multiple projects, each with their own Redis server.
Running Multiple Processes With Honcho
Honcho provides the ability to run
multiple processes (e.g. Django server, tailwind cli) as described in a
Procfile. There is a custom management command that makes running
all of the processes specified in the Procfile convenient - uv run manage.py dev.
Testing With Docker
To test the container before deployment the docker compose file can be used to build and deploy the container locally. There is also a settings file that is used to configure the application for running in the containerized environment.
To build, run, and create the "admin" user in the containerized environment run the following.
docker compose -f docker/compose.yml builddocker compose -f docker/compose.yml up -ddocker compose -f docker/compose.yml exec app /bin/bashsource .venv/bin/activateexport DJANGO_SETTINGS_MODULE=core.settings.localdockeruv run manage.py createsuperuser