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

  • Home
  • SEARCH
  • 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 5960587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:50:48+00:00 2026-05-22T18:50:48+00:00

(this isn’t duplicate of Changing Django settings variable dynamically based on request for multiple

  • 0

(this isn’t duplicate of “Changing Django settings variable dynamically based on request for multiple site”, as that previous question covers making much more serious reconfiguration at runtime)

I use sites.Site to tie content to domains/host in my project (via foreign key). Choosing appropriate Site based on request.META['HTTP_HOST'] takes place in my custom middleware.

However, I’m aware that such use of sites framework isn’t exactly The Canonical Way (I have one instance of application serving different data for different domains, while sites – AFAIK – was designed to work with several instances, one per each domain).

Element that bothers me the most is settings.SITE_ID – static setting that ties current instance of application with one Site (domain). This is used in several places, i.e. contrib.auth (to compose full, absolute url in password reset email).
So, it would be cool to dynamically change SITE_ID based on request.META['HTTP_HOST'].

So my question is:

Is changing SITE_ID dynamically (i.e. in middleware) considered a good idea?

Documentation states that altering settings at runtime is generally bad idea (here), but perhaps doing it in this case (in middleware called early enough) is fine.

(edit):

It works as expected locally (Django test client), but I’m considering concurrent requests in production environment with multiple threads and/or processes.

  • 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-22T18:50:49+00:00Added an answer on May 22, 2026 at 6:50 pm

    Why don’t you just turn off django.contrib.sites? If you remove that from INSTALLED_APPS, you should be fine.

    Specifically, any well-written apps should now be using the get_current_site function from django.contrib.sites.models. When the sites app isn’t installed, this function will just return an instance of a RequestSite object (not a model) which works similarly to a standard Site instance.

    To answer the original question though, editing settings dynamically is never a good idea.

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

Sidebar

Related Questions

This isn't the complete code, but it's the parts that are causing problems. I've
Maybe this isn't the best way to approach this... Working on an app that
Hoping this isn't a duplicate, I couldn't find an original question on the topic.
I hope this isn't a duplicate of a question itself, but the search terms
I apologize that this isn't a question on how to use Mathematica, but rather
EDIT: This isn't as trivial as you think. Consider the fact that each addition
This isn't legal: public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {}
This isn't a holy war, this isn't a question of which is better. What
This isn't as malicious as it sounds, I want to get the current size
This isn't a question but I thought I'd start a thread where links to

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.