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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:23:54+00:00 2026-06-15T09:23:54+00:00

In django it’s very common to use a local_settings.py file to supplement settings.py so

  • 0

In django it’s very common to use a local_settings.py file to supplement settings.py so that each machine can have different settings. Usually people do something like this.

try:
    from local_settings import *
except ImportError:
    print "No local settings found!"

But the settings file usually contains large lists such as INSTALLED_APPS. If I want to add an app, I’d rather not copy the entire list into local_settings.py and modify it (makes for less readable code, and updating settings.py no longer affects any machine that re-writes INSTALLED_APPS). So I figured I could do something like this:

try:
    f = open('local_settings.py','r')
    exec f.read()
except IOError:
    print "No local settings found!"

Now local_settings.py no longer has to rewrite the entire INSTALLED_APPS variable:

INSTALLED_APPS.append('debug_toolbar')

I was under the impression that anytime you’re using exec or eval you’re probably doing something wrong. So my question is, is there anything wrong with this and is there a better way to do it?

  • 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-06-15T09:23:55+00:00Added an answer on June 15, 2026 at 9:23 am

    This is my technique:

    settings.py:

    try:
        from local_settings import *
    except ImportError:
        sys.exit("FATAL: No local settings file found.")
    

    local_settings.py

    import settings
    
    settings.INSTALLED_APPS += ('django_extensions',)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Django has a very handy test client /dummy web browser that one can use
Django only allows you to use one database in settings.py. Does that prevent you
Django (1.2 beta) will reset the database(s) between every test that runs, meaning each
Django uses real Python files for settings, Trac uses a .ini file, and some
Django objects aren't subscriptable meaning if you have user.name you can't define it with
Django seems to be falsely claiming that I have an error in my SQL
Django: how to use settings in templates?
Django allows auto database routing . It is possible to have different databases for
Django settings includes a list of python variables that are used for a plethora
Django can make use of multiple database engines at the same time. My problem

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.