Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3800822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:57:11+00:00 2026-05-19T13:57:11+00:00

I have modified the multihost.py middleware I found at http://effbot.org/zone/django-multihost.htm to set the settings.SITE_ID

  • 0

I have modified the multihost.py middleware I found at http://effbot.org/zone/django-multihost.htm to set the settings.SITE_ID dynamically, but have some concerns that I may have just left the reservation.

Most examples I have found for multiple domain hosting have been setup with multiple settings.py files hardcoded to their respective SITE_IDs.

Have I created a fix with a fatal flaw here? Will changing this value dynamically bite me on the a**.

from django.conf import settings
from django.contrib.sites.models import Site

class MultiHostMiddleware:

    def process_request(self, request):
        try:
            host_raw = request.META["HTTP_HOST"]
            colon = host_raw.find(':')
            if colon > -1:
                host = host_raw[0:colon]
            else:
                host = host_raw

            s = Site.objects.get(domain=host)
            if s:
                settings.SITE_ID = s.id

        except KeyError:
            pass # use default urlconf (settings.ROOT_URLCONF)

For the curious this is up and running so far, but has not stood up to actual traffic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:57:12+00:00Added an answer on May 19, 2026 at 1:57 pm

    The short, official answer is you’re not supposed to do this, though the docs don’t really explain why not.

    If you’re using a threaded server, I’d be concerned about a race condition. This should be quite simple to test; just put a call to sleep() in one view, then return an HttpResponse with the name of the current site. While the first view is sleeping, hit a different view on a different domain.

    If you use prefork, I don’t imagine that this would cause any problems. I’ve used this approach with matplotlib, since it’s easiest to set graph properties by changing global configuration with matplotlib.rcParams.update(). I use prefork fcgi, so I can safely assume that each request has the whole process to itself (folks, please correct me if I’m wrong).

    Edit: I think you can do what you want using RequestSite by disabling the sites application. James Bennett’s django-registration, for example, instantiates a RequestSite object in that case, which extracts the hostname from the request object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have modified my treeview to look like an Org chart using the example
I have modified the example found here to use two io channels. None of
//UPDATE// I found some code to do paging which I have modified to work
I have a gridview and have modified it following this article: http://msdn.microsoft.com/en-us/library/aa992036.aspx#Y3473 to allow
I have found a piece of code on the web and have modified it
I have php login script that I have modified with htm tables and css.
I have modified the Nerd Dinner application to allow editing of child records by
I have modified my MOSS 2007 configuration to query a given target AD successfully.
I have modified a working Windows service that had always been starting beforehand. After
I have modified a website with a redirection to a single page: RewriteCond %{REQUEST_FILENAME}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.