[Django]-Using Constants in Settings.py

17👍

You certainly can… it’s encouraged, in fact. To use it, import the settings from django.conf (this imports your project’s settings):

from django.conf import settings
print "My database host is %s" % settings.DATABASE_HOST

The documentation on Using settings in Python code explains why this works, and why this is preferable over importing the the settings.py module directly.

4👍

yes

from django.conf import settings

print settings.MY_SETTINGS_VAR

Leave a comment