Reputation: 42277
I'm getting the project path in my Django app in settings.py using:
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
I would like to use the PROJECT_PATH value in other views, such as for locating the path to files in my static path. How can I make this into an accessible variable?
Upvotes: 52
Views: 34229
Reputation: 1295
in settings.py
add
DOMAIN = "example.com"
views.py
from django.conf import settings
DOMAIN = settings.DOMAIN
lets try to output it
:
print(DOMAIN)
print(type(DOMAIN))
output will be
:
example.com
<class 'str'>
Upvotes: 8
Reputation: 5424
from django.conf import settings as conf_settings
project_path = conf_settings.PROJECT_PATH
Upvotes: 31
Reputation: 70198
Use from django.conf import settings
but mind that settings
is not a module. The documentation clearly explains that and your use case.
Upvotes: 65