Setting your environment variables
Below is an example of what your .env file might look like:
DB_HOST=postgres
DB_NAME=shipwithdjango
DB_PASSWORD=Abc123!!
DB_USER=postgres
DB_PORT=5432
DEBUG=True
EMAIL_HOST=smtp.office365.com
EMAIL_PORT=587
[email protected]
EMAIL_HOST_USER_NAME="Example Name"
EMAIL_HOST_PASSWORD=examplepassword
EMAIL_USE_TLS=True
SENDGRID_API_KEY=your_sendgrid_api_key_here
REDIS_HOST=redis
SECRET_KEY=your_secret_key_here
STRIPE_LIVE_MODE=False
STRIPE_PUBLIC_API_KEY=your_stripe_public_key_here
STRIPE_SECRET_API_KEY=your_stripe_secret_key_here
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret_here
STRIPE_TEST_PUBLIC_API_KEY=your_stripe_test_public_key_here
STRIPE_TEST_SECRET_API_KEY=your_stripe_test_secret_key_here
STRIPE_TEST_WEBHOOK_SECRET=your_stripe_test_webhook_secret_here
OPENAI_API_KEY=your_openai_api_key_hereIt is not necessary to modify all these variables at once. You can update them as needed based on the specific requirements of your application. Below is a breakdown of the key sections and what each set of environment variables controls.
Database
These variables define the connection details for your application's database:
DB_HOST: The hostname of your database server. If using Docker, this should be set topostgres, matching the service name in the Docker Compose file.DB_NAME: The name of the database your application will use.DB_USER: The username for accessing the database.DB_PASSWORD: The password for the database user.DB_PORT: The port number on which your database server is listening (default is 5432 for PostgreSQL).
Debug
The DEBUG variable controls the debugging mode of your application:
DEBUG: Set this toTrueduring development to enable detailed error pages and logs. Important: Set this toFalsebefore deploying your application to production to prevent exposure of sensitive information.
Email
These variables configure your application's email delivery settings:
EMAIL_HOST: The SMTP server your application will use to send emails.EMAIL_PORT: The port on which the SMTP server is running.EMAIL_HOST_USER: The username for the SMTP server.EMAIL_HOST_USER_NAME: The name that will appear in the "From" field of outgoing emails.EMAIL_HOST_PASSWORD: The password for the SMTP server.EMAIL_USE_TLS: Whether to use TLS for secure email transmission (TrueorFalse).SENDGRID_API_KEY: If using SendGrid for email, set your API key here.
If using SMTP, ensure that the EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER, EMAIL_HOST_USER_NAME, and EMAIL_HOST_PASSWORD are configured.
For SendGrid, use EMAIL_HOST_USER, EMAIL_HOST_USER_NAME, and SENDGRID_API_KEY.
Redis
The REDIS_HOST variable specifies the address of your Redis instance:
REDIS_HOST: If using Docker, set this toredis, which matches the service name in the Docker Compose file.
Secret Key
The SECRET_KEY is a critical component for the security of your Django application:
SECRET_KEY: This should be a unique, secret key used for cryptographic signing. You can generate a strong secret key here.
Stripe
To enable payment processing and subscription management, configure the following Stripe-related environment variables:
STRIPE_LIVE_MODE: Set toTrueto enable live mode, orFalsefor testing.STRIPE_PUBLIC_API_KEY: Your public Stripe API key for live mode.STRIPE_SECRET_API_KEY: Your secret Stripe API key for live mode.STRIPE_WEBHOOK_SECRET: The webhook secret for Stripe in live mode.STRIPE_TEST_PUBLIC_API_KEY: Your public Stripe API key for test mode.STRIPE_TEST_SECRET_API_KEY: Your secret Stripe API key for test mode.STRIPE_TEST_WEBHOOK_SECRET: The webhook secret for Stripe in test mode.
Ensure these variables are correctly set to integrate Stripe into your application effectively.
OpenAI
To enable OpenAI capabilities, set the OPENAI_API_KEY to your key.
By configuring these environment variables, you can fine-tune how ShipWithDjango operates, ensuring it meets your project's specific needs.
Last updated