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 440127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:50:30+00:00 2026-05-12T20:50:30+00:00

Here is my situation… I am trying to dynamically generate a bunch of stuff

  • 0

Here is my situation…

I am trying to dynamically generate a bunch of stuff in my settings.py file on a django site.

I am setting up several sites, (via sites framework) and I want to have some values I plug in to a function that will generate a portion of the settings file for each site.

for example:

from universal_settings import *

SITE_NAME = 'First Site'
SITE_SLUG = 'firstsite'

DEFAULT_FROM_EMAIL = '%s <noreply@otakupride.com>' % SITE_NAME
ROOT_URLCONF = 'mysite.urls.%s' % SITE_SLUG
TEMPLATE_DIRS += ( os.path.join(PROJECT_ROOT, "templates", SITE_SLUG), )

obviously it’s a huge violation of DRY to have those last 3 lines in the settings file for every site running this code. So I want to do something like this

from universal_settings import *
from utils import get_dynamic_settings

SITE_NAME = 'First Site'
SITE_SLUG = 'firstsite'

get_dynamic_settings( locals() )

And here is the function

# WARNING: THIS CODE DOES NOT WORK!
def get_dynamic_settings(context_dict):
    global DEFAULT_FROM_EMAIL
    global ROOT_URLCONF
    global TEMPLATE_DIRS

    DEFAULT_FROM_EMAIL = '%s <noreply@otakupride.com>' % context_dict['SITE_NAME']
    ROOT_URLCONF = 'mysite.urls.%s' % context_dict['SITE_SLUG']
    TEMPLATE_DIRS += ( os.path.join(PROJECT_ROOT, "templates", context_dict['SITE_SLUG']), )

so my question is… how do I add things to the scope of the settings file? it doesn’t seem to have a dict object available to the variables within it.

Maybe I’m going about this all wrong? Thanks for your help!

PS – my understanding of the global keyword is that it tells the compiler that the function means to manipulate a global variable within it’s own file – is there such a thing for the file which the function is called?

  • 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-12T20:50:30+00:00Added an answer on May 12, 2026 at 8:50 pm

    Dict returned by locals() (or globals()) is mutable, so you could do:

    def get_dynamic_settings(context_dict):
        context_dict['DEFAULT_FROM_EMAIL'] = '%s <noreply@otakupride.com>' % context_dict['SITE_NAME']
        context_dict['ROOT_URLCONF'] = 'mysite.urls.%s' % context_dict['SITE_SLUG']
        context_dict['TEMPLATE_DIRS'] += (os.path.join(PROJECT_ROOT, "templates", context_dict['SITE_SLUG']),)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very odd situation here. I'm trying to launch a .application file using Response.Redirect. In
I got a little confusing situation here when I use the Context from django.template.
Here is situation I have been trying to solve Lets take a Employee table
I'm having a bizarre situation here where my external site files, both JavaScript and
i got a tricky situation here. im trying to center 3 divs inside my
We have a little situation here. We are writing an ini file at install-time
I have a unique problem/situation here. Trying to make it as simple as possible.
Bumped into a strange situation here. Trying to extract cars from a sql database
Here's the situation: I have a menu that needs to be created dynamically from
Here is my situation. I would like to make writing to the file system

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.