Set up · 02
Configuration and secrets
Configuration is split between environment variables for infrastructure and database-backed settings for storefront behaviour. This page explains which value belongs where and which ones production refuses to start without.

Settings modules
| Module | Used by | Behaviour |
|---|---|---|
config.settings | Development, tests, management commands | Loads .env, defaults to SQLite unless POSTGRES_DB is set, and enables local static serving. |
config.settings_production | Gunicorn on the VPS | Forces DEBUG=False, requires PostgreSQL and a strong secret, enables HTTPS/HSTS/secure cookies, file logging and production host validation. |
Both modules import the same application settings. Production overrides the unsafe development defaults instead of maintaining a second application configuration.
Environment precedence
The base settings read .env from the application root, but only through os.environ.setdefault. A real environment variable always wins. systemd loads .env through EnvironmentFile=, so the running service sees the same values without the shell having to source the file.
# Inspect the effective production values without printing secrets
.venv/bin/python - <<'PY'
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings_production')
import django
django.setup()
from django.conf import settings
print(settings.DEBUG, settings.DATABASES['default']['ENGINE'])
print(settings.SITE_URL, settings.SHORTLINK_DOMAIN)
PYDo not commit .env. The production template is deploy/env.production.example; the local template is .env.example.
Core values
| Variable | Production requirement | Why it matters |
|---|---|---|
DJANGO_SECRET_KEY | Required, 50+ characters, 5+ unique, no django-insecure- prefix | Signs sessions, password reset tokens and security primitives. |
DJANGO_ALLOWED_HOSTS | Canonical domain, www and optional short host | Rejects unknown Host headers. |
DJANGO_CSRF_TRUSTED_ORIGINS | Full https:// origins | Allows authenticated form posts behind TLS. |
SITE_URL | Must start with https:// | Canonical links in email, affiliate and share surfaces. |
SHORTLINK_DOMAIN | Optional subdomain of SITE_URL | Enables go.example.com/<code>; otherwise use /i/<code>/. |
DB_ENGINE | postgresql on the VPS | sqlite is reserved for local production-equivalence checks. |
Database
Development uses SQLite when no POSTGRES_DB is present. To use PostgreSQL locally, set the POSTGRES_* values. Production uses the DB_* names and defaults to PostgreSQL with connection reuse and health checks.
DB_ENGINE=postgresql
DB_NAME=perfumz
DB_USER=perfumz
DB_PASSWORD=change-me
DB_HOST=127.0.0.1
DB_PORT=5432
DB_CONN_MAX_AGE=600The production settings raise ImproperlyConfigured when DB_NAME is missing or the engine is unsupported. The readiness endpoint runs SELECT 1 and reports the database check in JSON.
Email and providers
| Area | Primary variables | Notes |
|---|---|---|
DJANGO_EMAIL_*, DEFAULT_FROM_EMAIL, TRANSACTIONAL_EMAIL_PROVIDER | SMTP is the default. Optional Resend, SendGrid, Postmark and Mailgun keys are read by the mailer. | |
| Payments | STRIPE_*, FLW_*, PAYPAL_*, PAYMENT_PROVIDER | Configure only the provider you intend to offer. Webhook secrets are required for signed callbacks. |
| Newsletter | NEWSLETTER_ESP, MAILCHIMP_* | Local capture is the default; Mailchimp adds list sync and webhook processing. |
| Push | VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY, VAPID_SUBJECT | Generate a pair with python manage.py generate_vapid_keys. |
| AI | AI_PROVIDER, OPENAI_API_KEY, OPENAI_MODEL | local keeps the assistant deterministic; openai enables hosted generation. |
Database-backed settings
Storefront copy, logo URLs, currency, tax, free-shipping threshold, low-stock threshold, order prefix, payment provider, cookie consent, SEO defaults, social links and feature flags live in SiteSettings. Edit them at /dashboard/settings/. Theme colours, logos and typography live in the Content Studio theme panel and ThemeSettings.
Changing a database-backed setting does not require a deploy. Changing an environment variable does require a service restart because systemd reads .env at start and Gunicorn loads settings once per worker.
The settings workbench can send a test email and shows integration health. It never displays or stores provider secrets in the browser.
Production guardrails
.venv/bin/python manage.py check --deploy --settings config.settings_production
bash deploy/verify.shcheck --deploy must report no warnings. deploy/verify.sh runs the production settings against a temporary database and Gunicorn, including the HTTPS redirect, HSTS, frame headers and readiness probes.