⚡ FastAPI / Flask
Beginner
How do you handle environment configuration in Flask?
Answer
Flask configuration is managed through the app.config dictionary. Best practices: Class-based config: create a config.py with classes for each environment: class DevelopmentConfig: DEBUG = True; SQLALCHEMY_DATABASE_URI = 'sqlite:///dev.db'. Load with app.config.from_object(DevelopmentConfig). Environment variables: use python-dotenv to load a .env file: from dotenv import load_dotenv; load_dotenv(). Read variables: os.environ.get('SECRET_KEY'). Instance folder: store sensitive local config in instance/config.py (not committed to git). Load with app.config.from_pyfile('config.py'). The FLASK_ENV and FLASK_DEBUG environment variables control development/production mode. Never hardcode secrets in source code.