Environment File Locations
Depending on your deployment method, environment variables are stored in different locations:- Docker
- Bare Metal
Split into two files:
.envs/.production/.django- Django application settings.envs/.production/.postgres- PostgreSQL database settings
Use deploy/env.example as your template. It contains all available variables with descriptions.
Required Variables
These variables must be set for production deployment:Django Core Settings
Database Configuration
Docker - Separate PostgreSQL Variables
Docker - Separate PostgreSQL Variables
If using Docker, also create
.envs/.production/.postgres:Redis Configuration
Security Settings
Configure security headers and HTTPS enforcement:SSL/TLS Settings
These settings are validated by Django’s deployment checks in config/checks.py:334.
Content Security Policy (CSP)
API Rate Limiting
Email Configuration
FootyCollect uses SendGrid for email delivery:Get SendGrid API Key
Get SendGrid API Key
- Sign up at SendGrid
- Navigate to Settings > API Keys
- Create a new API key with “Mail Send” permissions
- Copy the key (shown only once)
- Add to
SENDGRID_API_KEY
Verify Sender Domain
Verify Sender Domain
- In SendGrid, go to Settings > Sender Authentication
- Verify your domain (yourdomain.com)
- Add DNS records as instructed
- Use verified domain in
DJANGO_DEFAULT_FROM_EMAIL
Storage Configuration
Configure S3-compatible storage for static and media files:Storage Backend Selection
AWS S3 Storage
Create S3 Bucket
Create S3 Bucket
- Log into AWS Console
- Navigate to S3 > Create bucket
- Choose a unique bucket name
- Select region (e.g., us-east-1)
- Uncheck “Block all public access” (static files need public read)
- Create bucket
Create IAM User
Create IAM User
- Navigate to IAM > Users > Add user
- Enable “Programmatic access”
- Attach policy:
AmazonS3FullAccess(or create custom policy) - Save Access Key ID and Secret Access Key
- Add to environment variables
Configure Bucket Policy
Configure Bucket Policy
Add public read policy for static files:
Cloudflare R2 Storage
Create R2 Bucket
Create R2 Bucket
- Log into Cloudflare Dashboard
- Navigate to R2 > Create bucket
- Choose a bucket name
- Create bucket
Generate API Token
Generate API Token
- In R2, go to Manage R2 API Tokens
- Create API token
- Set permissions: Read and Write
- Save Access Key ID and Secret Access Key
- Note the endpoint URL (contains your account ID)
Configure CORS (Required for Fonts)
Configure CORS (Required for Fonts)
If serving fonts or static assets from a custom domain, configure CORS:Or manually add in Cloudflare Dashboard > R2 > bucket > Settings > CORS Policy.
Setup Custom Domain
Setup Custom Domain
- In R2 bucket settings, click “Connect Custom Domain”
- Enter your subdomain (e.g., cdn.yourdomain.com)
- Add CNAME record to your DNS:
- Type: CNAME
- Name: cdn
- Target: (provided by Cloudflare)
- Set
CLOUDFLARE_R2_CUSTOM_DOMAIN=cdn.yourdomain.com
Why Cloudflare R2? R2 offers S3-compatible API with free egress (no bandwidth charges), significantly reducing costs compared to AWS S3.
Error Tracking (Sentry)
Configure Sentry for error monitoring and performance tracking:Setup Sentry
Setup Sentry
- Sign up at Sentry.io
- Create a new project (Django)
- Copy the DSN from project settings
- Add to
SENTRY_DSN
Configure Sample Rate
Configure Sample Rate
SENTRY_TRACES_SAMPLE_RATE controls performance monitoring:0.0- Disabled (no performance tracking)0.1- 10% of requests tracked1.0- 100% of requests tracked (high volume)
0.0 or 0.1 to avoid quota limits.External Integrations
Football Kit Archive API (FKAPI)
FKAPI is optional but provides Football Kit Archive integration for searching and adding kits. See FKAPI repository for setup.
Rotating Proxy (Optional)
When to Use Rotating Proxy
When to Use Rotating Proxy
Use a rotating proxy if:
- Downloading many images from external sources
- Getting rate-limited by image hosts
- Need to distribute requests across multiple IPs
Performance Settings
Compression
Connection Pooling
CONN_MAX_AGE=60 keeps database connections alive for 60 seconds, reducing connection overhead. Set to 0 to disable pooling.Complete Environment File Example
Here’s a complete production environment file (deploy/env.example:1):View Complete .env Example
View Complete .env Example
Environment File Security
File Permissions
Version Control
Credential Rotation
- Rotate
DJANGO_SECRET_KEYperiodically (requires user re-login) - Rotate database passwords quarterly
- Rotate API keys when team members leave
- Use unique credentials per environment (dev/staging/prod)
Secrets Management
For enhanced security, consider using:- AWS Secrets Manager - Store credentials in AWS
- HashiCorp Vault - Centralized secrets management
- Environment-specific encryption - Encrypt .env files at rest
Validation
Verify your environment configuration:Django Deployment Checks
- ✓ DEBUG is disabled
- ✓ SECRET_KEY is secure (length, uniqueness)
- ✓ Required environment variables are set
- ✓ Database connectivity
- ✓ Redis connectivity
- ✓ Storage credentials (S3/R2)
- ✓ ALLOWED_HOSTS configured
- ✓ SSL/HTTPS settings
Manual Verification
Environment Variables Reference
Quick Reference Table
See deploy/env.example:1 for the complete list with descriptions.
Next Steps
Docker Deployment
Deploy with Docker Compose using environment files
Bare Metal Deployment
Deploy on VPS with environment file
Production Checklist
Verify configuration with deployment checklist