Serve Multiple Domains from a Single Django Project


Within this article we will be showing you the necessary steps required to serve multiple domains from within a single Django project.
This example will based upon a project named ‘myproject’ and 2 domains named ‘domain1’ and ‘domain2’. Below shows the file structure.

`-- django
    `-- myproject
        |-- domain1
        |   |--
        |   |-- domain1.wsgi
        |   |--
        |   |--
        |   |--
        |   |--
        |   |--
        |-- domain2
        |   |--
        |   |-- domain2.wsgi
        |   |--
        |   |--
        |   |--
        |   |--
        |   |--
        |-- templates
        |   |-- domain1-base.html
        |   |-- domain2-base.html


First of create a new Apache configuration file within ‘/etc/httpd/conf.d/’ named ‘django.conf’

import os
import sys
from django.core.handlers.wsgi import WSGIHandler


os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘domain1.domain1_settings’ #->change to ‘domain2.domain2_settings’ for domain2
application = WSGIHandler()


Now you will need to create a settings file for each domain,


Below shows an example of ‘/opt/django/myproject/domain1/’. For the domain2 settings file amend the ‘SITE_ID’ to ‘2’ and the ‘ROOT_URLCONF’ accordingly.

from settings import *

SITE_ID = 1   #-> change to SITE_ID = 1 for domain2

ROOT_URLCONF = ‘domain1.domain1_urls’   #-> change to ‘domain2.domain2_urls’ for domain2



Next create the following files,


Below shows an example of ‘/opt/django/myproject/domain1/’. For the domain2 urls update the ‘’ file accordingly.

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns(”,
url(r’^domain1_base/$’, ‘domain1.views.base’), #-> update accordingly for domain2

Final Step

Finally restart Apache (i.e ‘/etc/init.d/httpd restart’). You will now be able to browse to both domain1 and domain2 via your single project.

Note : Apache will need to be restarted once any of the above configuration files are amended.

Rick Donato

Want to become a Django expert?

Here is our hand-picked selection of the best courses you can find online:
The Complete Web Development Bootcamp course
Django Practical Guide course
Django Full Stack Developer Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial