Different settings for each application with Djang

2020-06-27 05:54发布

问题:

How do I use different setting for each application?

For example:

  • http://www.mysite.com/app1 uses the settings.py + local_settings.py of the app1's folder...

  • http://www.mysite.com/app2 uses the settings.py + local_settings.py of the app2's folder...

etc...

Thanks,

回答1:

you could check all ways of splitting up your settings from here: https://code.djangoproject.com/wiki/SplitSettings



回答2:

Older relevant thread talking about per application settings:

http://groups.google.com/group/django-developers/browse_thread/thread/fc8b2e284459f6cf

You can run multiple django instances on a single domain with different settings using the advice from here:

multiple instances of django on a single domain



回答3:

It's not pretty, but you can put the following in your settings.py after INSTALLED_APPS:

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
for app in INSTALLED_APPS:
    local_settings = os.path.join(PROJECT_DIR, app, 'local_settings.py')
    if os.path.isfile(local_settings):
        execfile(local_settings)