Skip to main content

Overview

Bar Galileo uses environment variables for configuration management. Variables are loaded from a .env file located at bar_galileo/bar_galileo/.env using the python-dotenv package.

Environment File Location

bar_galileo/
└── bar_galileo/
    ├── .env              # Environment configuration
    ├── settings.py
    ├── wsgi.py
    └── asgi.py

Quick Setup

1

Create .env file

Create the environment file in the correct location:
touch bar_galileo/bar_galileo/.env
2

Add required variables

Copy the template below and customize values:
nano bar_galileo/bar_galileo/.env
3

Restart Django

Restart the server to load new configuration:
python manage.py runserver

Environment Variables Reference

Core Django Settings

DEBUG
boolean
default:"True"
Enable or disable Django debug mode.Accepted values: 1, true, yes, True (case-insensitive)Production: Must be False
secret_key
string
required
Django secret key for cryptographic signing.Security: Keep this value secret. Never commit to version control.Generation: Use Django’s get_random_secret_key() or:
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
ALLOWED_HOSTS
string
default:"* (if DEBUG=True)"
Comma-separated list of host/domain names that Django can serve.Format: localhost,example.com,www.example.comExample: localhost,bar-galileo.com,192.168.1.100
In production, ALLOWED_HOSTS must be explicitly set to your domain names. Never use * in production.

Database Configuration

DB_NAME
string
default:"bar_galileo"
MySQL/MariaDB database name.
DB_USER
string
default:"bar_galileo_user"
MySQL/MariaDB database user.
DB_PASSWORD
string
default:"Galileo2025"
MySQL/MariaDB database password.Security: Use a strong password in production.
DB_HOST
string
default:"localhost"
MySQL/MariaDB database host.Examples: localhost, 127.0.0.1, db.example.com
DB_PORT
string
default:"3306"
MySQL/MariaDB database port.

Email Configuration

emailHost
string
required
Gmail email address for sending system emails.Example: [email protected]
emailPassword
string
required
Gmail App Password (not your regular Gmail password).How to generate:
  1. Enable 2-factor authentication on your Google account
  2. Visit https://myaccount.google.com/apppasswords
  3. Generate a new app password
  4. Use the 16-character password in this field
Gmail App Passwords are different from your regular password. You must enable 2FA to generate app passwords.

Environment File Templates

Development Template

# Django Core Settings
DEBUG=True
secret_key=your-secret-key-here
ALLOWED_HOSTS=localhost,127.0.0.1

# Database Configuration
DB_NAME=bar_galileo
DB_USER=bar_galileo_user
DB_PASSWORD=your_password_here
DB_HOST=localhost
DB_PORT=3306

# Email Configuration
emailHost=[email protected]
emailPassword=your-app-password-here

Database Setup

MySQL/MariaDB Initial Configuration

After setting environment variables, create the database:
CREATE DATABASE bar_galileo 
  CHARACTER SET utf8mb4 
  COLLATE utf8mb4_unicode_ci;

Production Security Checklist

Before deploying to production, verify all security settings:
1

Set DEBUG=False

DEBUG=False
This disables debug pages and protects sensitive information.
2

Generate secure SECRET_KEY

python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
Use a unique, random key for production.
3

Configure ALLOWED_HOSTS

ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
Only include your actual domain names.
4

Use strong database password

DB_PASSWORD=STRONG-RANDOM-PASSWORD-HERE
Never use the default password in production.
5

Set up SSL/HTTPS

Ensure your server has a valid SSL certificate. Security settings are auto-enabled when DEBUG=False:
  • SECURE_SSL_REDIRECT = True
  • SESSION_COOKIE_SECURE = True
  • CSRF_COOKIE_SECURE = True
  • SECURE_HSTS_SECONDS = 31536000

Auto-Enabled Production Settings

When DEBUG=False, these security features are automatically enabled:
settings.py
if not DEBUG:
    SECURE_SSL_REDIRECT = True                    # Force HTTPS
    SESSION_COOKIE_SECURE = True                  # Secure session cookies
    CSRF_COOKIE_SECURE = True                     # Secure CSRF cookies
    SECURE_HSTS_SECONDS = 31536000                # HSTS for 1 year
    SECURE_HSTS_INCLUDE_SUBDOMAINS = True         # HSTS for subdomains
    SECURE_HSTS_PRELOAD = True                    # HSTS preload list
    SECURE_REFERRER_POLICY = 'strict-origin-when-cross-origin'

Environment Variable Loading

Bar Galileo loads environment variables using python-dotenv:
settings.py
from dotenv import load_dotenv
from pathlib import Path

load_dotenv(dotenv_path=Path(__file__).resolve().parent / '.env')

Variable Access in Code

import os

# Get variable with default
db_name = os.getenv('DB_NAME', 'bar_galileo')

# Get required variable
secret = os.getenv('secret_key')

# Boolean conversion
debug = str(os.getenv('DEBUG', 'True')).lower() in ('1', 'true', 'yes')

# List conversion (comma-separated)
raw_hosts = os.getenv('ALLOWED_HOSTS', '')
hosts = [h.strip() for h in raw_hosts.split(',') if h.strip()]

Common Issues

.env File Not Found

If environment variables aren’t loading:
1

Check file location

The .env file must be in bar_galileo/bar_galileo/.env (same directory as settings.py)
2

Verify file name

Ensure the file is named exactly .env (not env.txt or .env.example)
3

Check file permissions

chmod 600 bar_galileo/bar_galileo/.env

Database Connection Errors

Check DB_USER and DB_PASSWORD are correct:
mysql -u bar_galileo_user -p
Enter the password from your .env file.
Create the database:
CREATE DATABASE bar_galileo CHARACTER SET utf8mb4;
Check DB_HOST and DB_PORT:
mysql -h localhost -P 3306 -u bar_galileo_user -p

Email Configuration Issues

Check that EMAIL_PORT=587 and EMAIL_USE_TLS=True are set correctly in settings.py

Default Values Summary

VariableDefault ValueRequiredEnvironment
DEBUGTrueNoAll
secret_keyAuto-generatedYes (production)All
ALLOWED_HOSTS* (if DEBUG)Yes (production)All
DB_NAMEbar_galileoNoAll
DB_USERbar_galileo_userNoAll
DB_PASSWORDGalileo2025Yes (production)All
DB_HOSTlocalhostNoAll
DB_PORT3306NoAll
emailHostNoneYesAll
emailPasswordNoneYesAll

Security Best Practices

Never Commit .env

Add .env to .gitignore to prevent accidental commits

Use Strong Passwords

Generate secure random passwords for production

Rotate Secrets

Regularly update SECRET_KEY and passwords

Limit Permissions

Use restricted database user permissions in production

Django Settings

Complete Django settings reference

Deployment Guide

Production deployment instructions

Build docs developers (and LLMs) love