Django settings: How to access variables from the settings folder in an app

Micah Pearce

I have a djanog project with the following structure:

--|src
  --project
  --|settings
     --__init__.py
     --production.py
     --local.py
  --|app1

In my app I import the settings (from django.conf import settings) and then as I was following a tutorial they said to do this getattr(settings, VARIABLE). That doesn't work for me. Instead I can do this: settings.VARIABLE. What's the difference?

Oh and I ran type(settings) and it outputted <class 'django.conf.LazySettings'>.

Mohammad Ali

in order to access variables in settings.py file, you can do like this:

for example, I define STATIC_ROOT variable in settings.py file like this:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static', 'static_root')

and I can access to this variable like this:

from django.conf import settings
document_root=settings.STATIC_ROOT

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can I access constants in settings.py from templates in Django?

How to print BASE_DIR from settings.py from django app in terminal?

Slim 3: how to access settings?

how deploy uwp app with settings

How to access accessibility settings in MacOSX Cocoa app using swift?

How to set mailSettings from Azure App Service - Application settings

How to receive data from App Settings Azure (webapp) to my webjob

How to exclude app settings from a docker image (and add them to the container)?

How to run django-pytest on a project which imports settings from environment variables defined in manage.py

How to access settings from `.env` inside the `index.php`

How to get my app settings folder path for the current user?

How to link to phone settings from react native app

Django path to templates folder in settings.py

Dynamically set Django settings variables from Database

How change the fixed CI/CD variables from repo settings by request?

Django: settings for tests of a reusable app?

How to access BIOS settings with EFI?

How to access the settings in iOS

How to display only specific Settings fragment from android inbuilt Settings app

Populating combobox from app settings

Wordpress and Woocmmerce - how to access settings from theme?

how to properly import django project settings to interact with app's ORM?

How to access Default Settings from user control?

How to get the Azure Webapp App Settings from Django

Django custom settings for app

How to get to text app settings?

How to access Unity settings from Java/Android?

How to access all user settings from the google api?

How to access Heroku config variables inside Django settings