I'm just getting started with Python's pyramid framework and am unsure where to set application variables and the best way to import them into my project. For example: database username/passwords, paths, thumbnail height/width, etc ...
Should I create a dedicated config.py file and import the variables into my functions? What should this look like?
Thanks.
There is a recipe in the cookbook for emulating the Django-style global settings file (for your convenience). However, the recommended way is to store these things in your INI file as deployment settings. Thus you could have one database username/password for development and one for production and it's as simple as having two INI files. All of the key/value pairs that you add to the [app:...]
INI section for your Pyramid app are available at setup time and during request processing via a settings
dictionary which is attached to the registry
. This is accessible via config.registry.settings
as well as request.registry.settings
. The settings
object is a copy of the dict
that you passed into the Configurator(settings=settings, ...)
within your main
function.
For more information, see http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/startup.html as well as the tutorials within the Pyramid documentation which have examples of all of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With