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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:20:40+00:00 2026-05-28T04:20:40+00:00

I was wondering about whether it is better to import variables into your view

  • 0

I was wondering about whether it is better to import variables into your view from the settings.py file? or better to create a configuration file with the variables that are needed?

I tend to like to write configuration files for my Django applications, read, and import the variables from there when necessary. For example:

.configrc

[awesomeVariables]
someMagicNumber = 7

views.py

from ConfigParser import SafeConfigParser
#Open and parse the file
config = SafeConfigParser()
config.read(pathToConfig)
#Get variable
magicNumber   = config.get('awesomeVariables', 'someMagicNumber'))

However, I’ve noticed some programmers prefer the following :

settings.py

SOME_MAGIC_NUMBER=7

views.py

import settings
magicNumber = settings.SOME_MAGIC_NUMBER

I was curious as to the pros and cons of the different methods? Can importing variables directly from your settings compromise the integrity of the architecture?

  • 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-28T04:20:41+00:00Added an answer on May 28, 2026 at 4:20 am

    It’s a judgement call. Using the settings module is the “Django way”, although you should do from django.conf import settings; settings.MY_SETTING, which will respect DJANGO_SETTINGS_MODULE. But Django is just Python; there’s nothing that will stop you from using ConfigParser. In the interest of having only one place where such things are defined, I’d recommend putting it in the Django settings file – but if you have a reason not to, don’t.

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

Sidebar

Related Questions

I've always wondered about this, and now a client is wondering whether it's feasable:
Just wondering about the performance impact of copying very large php variables. For example
I was wondering specifically about whether ItemCreated or ItemBound happens first but I can't
Without getting into a discussion about whether the business logic should be in the
I recently read about quicksort and was wondering whether it would be smart to
I'm wondering whether situation exists where casting is completely necessary. I'm talking here about
I'm wondering about instances when it makes sent to use #define and #if statements.
I'm wondering about MP3 decoding/encoding, and I was hoping to pull this off in
I've been wondering about the performance improvements touted in Java SE 6 - is
I'm wondering about the practical use of #undef in C. I'm working through K&R,

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.