django-project-core-settings
Secure, environment-aware Django project defaults with optional form/session and API/JWT authentication. The package is a foundation: your project owns its user model, URLs, templates, deployment platform, and operational policy.
Start quickly
py -m venv .venv
.\.venv\Scripts\Activate.ps1
py -m pip install "django-project-core-settings"
django-admin startproject config .
Import django_project_core_settings in the project settings module, add a project user app, and include django_project_core_settings.auth.urls. For the full beginner-to-production walkthrough, see docs/00_START_HERE.md. For API/JWT install [api], set CORE_ENABLE_API=true, and include django_project_core_settings.auth.api_urls.
Guided documentation
- Start here — guided installation and configuration path
- API/JWT, production setup, and security testing
- Verified development projects: session and API
- Deployment reference: examples/production_project
Version 1.0.2 requires Python 3.12+ and Django 6.1.x. The optional API extra requires Django REST framework 3.18.x and SimpleJWT 5.5.x; the Redis extra requires django-redis 7.x. Documentation is not a production-readiness certification; validate your application, infrastructure, secrets, TLS termination, backups, and monitoring.
Release validation runs scripts/verify_release_artifacts.py against built
wheel and sdist files; it creates clean environments, installs the base and
full extras, and smoke-tests API/JWT routes without an editable install.
One package. Secure defaults. Minimal project settings.
This is the clean-room consolidation of the two supplied packages:
django-project-core-settingsdjango-did-auth
The new design keeps the useful behavior from both packages but removes the hard coupling that made the original setup fragile.
What changed
1. One distribution
Install one package:
python -m pip install "django-project-core-settings"
For API/JWT support:
python -m pip install "django-project-core-settings[api]"
For API + CORS + Redis:
python -m pip install "django-project-core-settings[full]"
2. Environment selection is automatic
Set only:
DJANGO_ENV=dev
Supported values:
devprodtestlocalis accepted as a backwards-compatible alias fordev
3. Minimal settings.py
from django_project_core_settings import *
INSTALLED_APPS += ["users"]
AUTH_USER_MODEL = "users.CustomUser"
ROOT_URLCONF = "config.urls"
WSGI_APPLICATION = "config.wsgi.application"
ASGI_APPLICATION = "config.asgi.application"
The package supplies the security baseline. Project code adds only project-specific settings.
4. Form/session authentication
Add:
path("auth/", include("django_project_core_settings.auth.urls"))
The package provides:
- registration
- email verification
- login/logout
- password reset
- password change
- email authentication backend
- role-aware redirects
- role-required decorator
- cache-backed rate limiting
- audit logging
Browser session logout is POST /auth/logout/ only and requires Django's CSRF
token. Package templates render a sign-out form; do not link to the logout URL.
5. API/JWT authentication
Set:
CORE_ENABLE_API=true
Install the API extra and include:
path("api/auth/", include("django_project_core_settings.auth.api_urls"))
The API provides:
- login
- logout
- registration
- activation
- password reset
- password change
- profile
- role permission example
- JWT access/refresh tokens
- refresh-token rotation and blacklist support
The refresh endpoint is POST /api/auth/refresh/ and accepts a refresh
token. Rotation blacklists the submitted token and returns a replacement.
Security baseline
The package uses Django 6.1 security facilities rather than old third-party replacements wherever possible.
Defaults include:
- Argon2 first password hasher
- CSRF middleware
- secure session cookies in production
- secure CSRF cookies in production
HttpOnlysession cookieSameSite=Lax- clickjacking protection
- content-type sniffing protection
- strict referrer policy
- Cross-Origin Opener Policy
- HTTPS redirect in production
- HSTS in production
- built-in Django CSP middleware
- CSP nonce support instead of
unsafe-inline - upload size limits
- environment-based secrets
- generic password-reset responses
- no public role assignment during registration
- cache-backed authentication rate limits
- generic API authentication failures
- JWT signing key validation through configuration
- production secret key requirement
Django 6.1 has built-in CSP support, so this package does not depend on the older django-csp approach.
Important design rule
The package is a foundation, not a replacement for project settings.
Project settings can override any normal Django setting after the import:
from django_project_core_settings import *
DEBUG = False
ALLOWED_HOSTS = ["example.com"]
LOGIN_REDIRECT_URL = "/dashboard/"
For environment configuration, use .env:
ALLOWED_HOSTS=example.com,www.example.com
CSRF_TRUSTED_ORIGINS=https://example.com
Process environment variables take precedence over .env.
Why this architecture is safer
The supplied packages had several coupling and correctness problems:
- the settings package imported the authentication package directly;
- REST settings imported Redis-dependent authentication code during settings loading;
- Redis availability was checked during import;
localandprodbehavior overlapped;- CORS was configured as allow-all in local settings;
- CSP used
unsafe-inline; - the authentication package accepted a role from public API registration;
- API exception handlers returned internal exception details;
- API refresh logic depended on
request.usereven though refresh endpoints are normally unauthenticated; - the old activation flow required a custom
activation_token_createdfield on the project user model; django-ratelimitand Axes were coupled to the settings package even when a project did not need the full API/auth stack.
The new package avoids those startup dependencies and makes API, CORS, and Redis optional capabilities.
Configuration reference
| Variable | Default | Production behavior |
|---|---|---|
DJANGO_ENV |
dev |
use prod |
SECRET_KEY |
generated for dev/test | required |
DEBUG |
derived | False |
ALLOWED_HOSTS |
localhost in dev | set explicitly |
CORE_PUBLIC_ORIGIN |
http://localhost outside prod |
required HTTPS public origin for activation/reset email links |
CSRF_TRUSTED_ORIGINS |
empty | set for trusted HTTPS origins |
CORE_ENABLE_API |
false |
enable when using API |
CORE_ENABLE_CORS |
false |
enable only when needed |
CORE_ENABLE_REDIS |
false |
required when production authentication rate limiting is enabled |
CORE_REDIS_REQUIRED |
derived | fail cache operations when production rate limiting is enabled |
AUTH_VERIFY_HOURS |
24 |
override if required |
AUTH_RESET_SECONDS |
3600 |
override if required |
AUTH_LOGIN_RATE |
10/m |
login requests per IP |
AUTH_REGISTER_RATE |
5/m |
registration requests per IP |
AUTH_PASSWORD_RESET_RATE |
5/m |
password-reset requests per email |
AUTH_PASSWORD_CHANGE_RATE |
5/m |
password-change requests per user |
AUTH_ROLE_REDIRECTS |
empty | admin=/admin/,user=/dashboard/ style |
AUTH_DEFAULT_ROLE |
user |
project override |
AUTH_DENY_BEHAVIOR |
redirect |
use forbidden when preferred |
JWT_ACCESS_MINUTES |
15 |
project override |
JWT_REFRESH_DAYS |
1 |
project override |
Argon2 is a base dependency because it is the package's default password hasher. Authentication rate limiting deliberately refuses a production configuration without Redis enabled; local-memory counters cannot protect a multi-worker deployment. Redis must be reachable at runtime when required.
Authentication-rate setting rename
AUTH_RESET_RATE and AUTH_CHANGE_PASSWORD_RATE have been removed. Use
AUTH_PASSWORD_RESET_RATE and AUTH_PASSWORD_CHANGE_RATE instead. The old
names are intentionally not aliases, so configuration errors are not hidden by
unclear precedence.
User model contract
The package does not ship a user model. The project owns it.
For email authentication, the user model must expose an email field.
If role-based behavior is needed, add a role field or change:
AUTH_ROLE_FIELD=your_role_field
Do not expose the role as a public registration input.
Production deployment
Production startup requires an injected SECRET_KEY, explicit non-wildcard
ALLOWED_HOSTS, an HTTPS CORE_PUBLIC_ORIGIN, SMTP configuration, Redis for
authentication throttles, and a non-SQLite database engine/name. Use a
project-provided database driver (for example
psycopg for PostgreSQL), run python manage.py migrate including the
SimpleJWT blacklist migrations, and keep database/cache storage persistent.
CORE_PUBLIC_ORIGIN is the canonical scheme and host used for activation and
password-reset email links (for example, https://accounts.example.com). It
must not contain a path, query, or fragment. These links never use the request
Host header. Configure the origin for the externally reachable TLS endpoint;
CORE_TRUST_PROXY and CORE_TRUSTED_PROXY_CIDRS enable the package's validated
immediate-proxy middleware; forwarded identity is accepted only from a peer in the
configured CIDRs and does not alter email-link construction. DRF NUM_PROXIES
defaults to 0.
JWT_SIGNING_KEY is optional. When omitted, JWTs use SECRET_KEY; when set,
it is an independent signing key and must be rotated through your secret
manager with an application rollout. Password reset/change revokes existing
JWT credentials, so clients must sign in again.
TLS should terminate at Django or a controlled proxy. Set CORE_TRUST_PROXY=true
only with explicit CORE_TRUSTED_PROXY_CIDRS for a controlled immediate proxy.
Production trusted
origins and CORS origins must be HTTPS URLs. HSTS includeSubDomains and preload
are opt-in; preload requires includeSubDomains and one-year HSTS. Collect JSON audit logs from
standard output with your platform's log collector, test health endpoints in
the host project, and define project rollback/backup policy.
Runnable examples
Both session_project and
api_project include manage.py, a custom user app,
migrations, and .env.example. From either directory, install its
requirements.txt, copy .env.example to .env, then run python manage.py
migrate and python manage.py runserver.
See deployment guidance for production prerequisites, migrations, logging, and rollback responsibilities.
Example:
class CustomUser(AbstractUser):
username = None
email = models.EmailField(unique=True)
role = models.CharField(max_length=30, default="user")
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []
Updating the framework
Projects depend on the package, not copied framework code:
python -m pip install --upgrade django-project-core-settings
A framework security fix can therefore be shipped through the package without copying settings/authentication files into every project.
Verification
Run:
python manage.py check
python manage.py check --deploy
python manage.py test
For API projects:
python manage.py migrate
python manage.py check
python manage.py check --deploy
python manage.py test
License
MIT
Metadata
Release files for django-project-core-settings 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_project_core_settings-1.0.2.tar.gz | 47.9 kB | Without provenance | Details for django_project_core_settings-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_project_core_settings-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for django_project_core_settings-1.0.2-py3-none-any.whl |
Total release size: 88.2 kB
Release files / django_project_core_settings-1.0.2.tar.gz
| Download URL | django_project_core_settings-1.0.2.tar.gz |
|---|---|
| Size | 47.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57fcb0151fe65f937e54523c50b4818700b6e6d44fec71b7c76a47bbe3d79c34
|
|
BLAKE2b-256 checksum How to use checksums |
6d9096469d24ec73b9d98e6aac30bc32d5e09e77933830ea755eca616bc66548
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / django_project_core_settings-1.0.2-py3-none-any.whl
| Download URL | django_project_core_settings-1.0.2-py3-none-any.whl |
|---|---|
| Size | 40.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b35baefc2da5880d007e27267bf7e827480aee3f4d8d8d959f049acb3a95fcc
|
|
BLAKE2b-256 checksum How to use checksums |
06398f0eda5126d854d925be42108bf14c3bf03e574fb08cf1e4bcb66df30269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for django-project-core-settings 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.