views:

167

answers:

1

How can Django use different settings.py file based on subdomains.

Can these utilities ("django-admin", "python manage.py") still be used if there were different settings connecting to different databases.

+4  A: 

ok you have two dimensions you need to cover with your settings:

  1. Domain (site)
  2. Current Machine

Here is what I recommend:

universal_settings.py - all the settings you want to inherit everywhere (all machines, all domains)

local_settings.py - settings on a per machine basis (database settings, mail server, etc)

site_1.py - settings that are specific to a one of your domains
site_2.py - settings that are specific to a one of your domains
site_n.py - you get the idea

the bottom of universal_settings.py should include:

from local_settings import *

This will override anything in the universal settings as necessary.

similarly, each of the site_1.py, site_2.py, site_n.py settings files should begin with:

from universal_settings import *

Finally you need to set up an apache (or nginx, or whatever) instance for each domain and use the appropriate site_n.py as the settings file for that server

This is the method that works best for me :)

Jiaaro