A simple Django template.
Before you begin, ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/knowsuchagency/django-template.git cd django-template
-
Initialize the development environment:
just init
This will create a virtual environment, install dependencies, and set up the .env file.
To run the development server:
just runserver
Use just <command>
to run the following commands:
list
: Show all available commandsformat
: Format and fix code using ruff and prettierrunserver
: Run Django development servermakemigrations
: Create new database migrationsmigrate
: Apply database migrationsflush
: Flush the databasecreatesuperuser
: Create a Django superusercollectstatic
: Collect static files
For a full list of commands, run just list
.
This template includes a custom CSRF middleware that supports wildcard patterns in the CSRF_TRUSTED_ORIGINS
setting. This allows you to trust multiple subdomains without having to list each one individually.
Example configuration in .env
:
CSRF_TRUSTED_ORIGINS=https://*.example.com,https://example.com,http://localhost:8000
This will trust:
- Any subdomain of example.com (e.g., app.example.com, api.example.com)
- The root domain example.com
- localhost:8000
To use this feature, the custom middleware is already configured in the project's settings.