Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - How to share configuration constants within an app?

It is sometimes beneficial to share certain constants between various code files in a django application.

Examples:
- Name or location of dump file used in various modules\commands etc
- Debug mode on\off for the entire app
- Site specific configuration

What would be the elegant\pythonic way of doing this?

like image 410
Jonathan Livni Avatar asked Jul 14 '10 08:07

Jonathan Livni


2 Answers

There's already a project-wide settings.py file. This is the perfect place to put your own custom setttings.

like image 114
Daniel Roseman Avatar answered Oct 12 '22 05:10

Daniel Roseman


you can provide settings in your settings.py like

MY_SETTING = 'value'

and in any module you can fetch it like

from django.conf import settings
settings.MY_SETTING
like image 30
shahjapan Avatar answered Oct 12 '22 05:10

shahjapan