Overview
SASCOP BME SubTec uses environment variables to configure the application for different environments (development, staging, production). Variables are loaded usingpython-dotenv from a .env file.
Loading Environment Variables
Environment variables are loaded inbme_subtec/settings.py:1-5:
bme_subtec/settings.py
The
.env file is included in .gitignore and should never be committed to version control.Core Django Settings
SECRET_KEY
Required: YesDefault:
'django-insecure-bme-subtec-default-key-change-in-production'Purpose: Cryptographic signing key for Django security features
bme_subtec/settings.py
.env
DEBUG
Required: NoDefault:
TruePurpose: Enable/disable debug mode
bme_subtec/settings.py
.env
ALLOWED_HOSTS
Required: Yes (in production)Default:
['localhost', '127.0.0.1', '0.0.0.0', '*']Purpose: List of allowed host/domain names Current Configuration:
bme_subtec/settings.py
.env
Database Configuration
RDS_DB_NAME
Required: YesDefault:
'postgres'Purpose: Database name
bme_subtec/settings.py
.env
RDS_USERNAME
Required: YesDefault:
'postgres'Purpose: Database user
bme_subtec/settings.py
.env
RDS_PASSWORD
Required: YesDefault:
'' (empty string)Purpose: Database password
bme_subtec/settings.py
.env
RDS_HOSTNAME
Required: YesDefault:
'localhost'Purpose: Database host
bme_subtec/settings.py
.env
RDS_PORT
Required: NoDefault:
'5432'Purpose: Database port
bme_subtec/settings.py
.env
Email Configuration
EMAIL_HOST
Required: Yes (for email functionality)Default:
'smtp.gmail.com'Purpose: SMTP server hostname
bme_subtec/settings.py
.env
EMAIL_PORT
Required: NoDefault:
587Purpose: SMTP server port
bme_subtec/settings.py
.env
EMAIL_USE_TLS
Required: NoDefault:
TruePurpose: Use TLS encryption
bme_subtec/settings.py
.env
EMAIL_HOST_USER
Required: Yes (for email functionality)Default:
'' (empty string)Purpose: SMTP authentication username
bme_subtec/settings.py
.env
EMAIL_HOST_PASSWORD
Required: Yes (for email functionality)Default:
'' (empty string)Purpose: SMTP authentication password
bme_subtec/settings.py
.env
For Gmail, use an App Password rather than your regular password.
DEFAULT_FROM_EMAIL
Required: NoDefault:
'SASCOP <[email protected]>'Purpose: Default sender email address
bme_subtec/settings.py
.env
Payment Integration (OpenPay)
OPENPAY_MERCHANT_ID
Required: No (only if using OpenPay)Default:
'' (empty string)Purpose: OpenPay merchant identifier
bme_subtec/settings.py
.env
OPENPAY_PRIVATE_KEY
Required: No (only if using OpenPay)Default:
'' (empty string)Purpose: OpenPay API private key
bme_subtec/settings.py
.env
OPENPAY_PRODUCTION
Required: NoDefault:
FalsePurpose: Use OpenPay production environment
bme_subtec/settings.py
.env
Complete .env Template
Development Environment
.env.development
Production Environment
.env.production
Alternative Email Backend (Anymail)
The application includes support for django-anymail (SendGrid, Mailgun, etc.):bme_subtec/settings.py
SENDGRID_API_KEY
Required: No (only if using Anymail with SendGrid)Default:
'' (empty string)
Example:
.env
Platform-Specific Variables
Vercel
When deploying to Vercel, set environment variables in the Vercel dashboard or using the Vercel CLI:AWS
For AWS deployments, use Systems Manager Parameter Store or Secrets Manager:Docker
Pass environment variables to Docker containers:Security Best Practices
Use Strong Passwords
- Database passwords: At least 16 characters
- Secret keys: Use Django’s key generator
- API keys: Rotate regularly
Separate Environments
Use different credentials for each environment:
.env.development.env.staging.env.production
Rotate Credentials
Regularly rotate sensitive credentials, especially:
- Database passwords
- Secret keys (requires re-signing sessions)
- API keys
Validating Environment Variables
Create a management command to validate environment variables:core/management/commands/check_env.py
Next Steps
Deployment Overview
Learn about deployment strategies
Database Migrations
Manage database migrations in production