In pyramid, I need to render my templates according to different runtime environments — enable google analytics, use minified code, etc. (when in production). Is there an easy way to find out the current environment — perhaps an existing flag to find out which ini file was used?
In pyramid, I need to render my templates according to different runtime environments —
Share
Pyramid INI files can hold arbitrary configuration entries, so why not include a flag in your files that distinguishes between production and development deployments?
I’d do it like this; in your production .ini file:
Pass this value on to the Pyramid Configurator:
You can now access the settings from just about anywhere in your Pyramid code. For example, in a request handler:
However, I’d also use more finegrained settings in this case; a flag for enabling Google Analytics, one for minifying resources, etc. That way you can test each individual setting in your development environment, write unit tests for these switches, etc.