Config Classes per Environment
Define Dev, Test, and Prod settings.
Config Classes per Environment is a free Flask Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
One App, Many Worlds
Your app runs in different environments: your laptop, a test runner, and a live server. Each one needs its own settings.
What a Config Class Is
A config class is just a Python class whose attributes become Flask settings. Group related options together and read them in once.
class Config:
DEBUG = False
TESTING = FalseA Shared Base Class
Put values that every environment shares into a base Config class. Other environments will inherit from it and tweak what differs.
class Config:
SECRET_KEY = "changeme"
JSON_SORT_KEYS = FalseSubclass for Development
A DevelopmentConfig subclass flips on debugging so you see tracebacks and the auto reloader while you build.
class DevelopmentConfig(Config):
DEBUG = TrueSubclass for Testing
A TestingConfig turns on TESTING so errors propagate to your test runner instead of being swallowed.
class TestingConfig(Config):
TESTING = TrueSubclass for Production
A ProductionConfig keeps DEBUG off and points at the real database. Safety first when users are watching.
class ProductionConfig(Config):
DEBUG = FalseLoad It with from_object
Tell Flask which class to use with from_object. One line swaps your whole settings profile.
app.config.from_object(DevelopmentConfig)Read a Setting Back
Every attribute lands in app.config, a dict-like store. Read any value by its key whenever you need it.
value = app.config["DEBUG"]Map Names to Classes
A small config dict maps a short name to a class, so you can pick an environment by a single string.
config = {"dev": DevelopmentConfig, "prod": ProductionConfig}Choose by Name
Pick the active profile by name, often from an env var. The same code runs everywhere with no edits.
app.config.from_object(config[env_name])Never Hardcode Per Env
Avoid scattering if-checks across your code. Centralizing in config classes keeps environment logic in one place.
Quick Check
Where should settings shared by every environment live?
Recap: Config Classes
You built a base Config with per-environment subclasses, loaded one via from_object, and selected it by name. Clean and swappable! 🎯
Frequently asked questions
Is the “Config Classes per Environment” lesson free?
Yes — the full text of “Config Classes per Environment” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Config Classes per Environment”?
Define Dev, Test, and Prod settings. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Config Classes per Environment” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Config Classes per Environment
- Load Secrets from Environment Variables
- Use dotenv in Development
- Toggle Debug and Feature Flags