Category: python
configuration management and environment variables
Published on 30 Sep 2026
Explanation
Flask configuration stores application settings such as database URLs, debug settings, and secret keys.
Code:
app.config['DEBUG'] = True app.config['SECRET_KEY'] = 'development-key'
Explanation
Configuration values can be loaded from environment variables instead of hardcoding them in source code.
Code:
import os
SECRET_KEY = os.getenv('SECRET_KEY')
DATABASE_URL = os.getenv('DATABASE_URL')
Explanation
A .env file can be used during development to store environment-specific configuration values.
Code:
SECRET_KEY=dev-secret DATABASE_URL=sqlite:///app.db DEBUG=True
Explanation
python-dotenv can load values from a .env file into environment variables during development.
Code:
from dotenv import load_dotenv load_dotenv()
Explanation
Production secrets should not be committed to Git repositories. Use the deployment environment or a secret-management service.
Code:
Bad:
PASSWORD='myPassword123'
Better:
PASSWORD=os.getenv('DB_PASSWORD')