Question

Ex. in Symfony 1:

http://www.symfony-project.org/jobeet/1_2/Doctrine/en/06#chapter_06_custom_configuration

Where should I store global data, which file?

Was it helpful?

Solution

Depending on what kind of global data, it may make sense to put it as a constant in your settings.py file. For example, an organization's email or physical address, that is supposed to appear in many places.

However, it would be better to look for other ways (in the example above, perhaps putting it in a base.html template). I have seen django apps that grow to a large size end up with too many constants in the settings.py. My own personal rule of thumb is that if you have to look at more than one screen to find the setting you're wanting, there's too much in the settings.py.

One alternative is just to go ahead and make a database table of site-wide data. If your database has appropriate caching ability then the cost of loading this frequently is small. Also, if the configuration data is expected to change frequently, settings.py is not where you would want it. But for a few site-configuration pieces of data, that are not expected to be dynamically changed, settings.py could make sense as a place to put it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top