Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a variable from settings.py to a view?

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?

like image 1000
Geuis Avatar asked Oct 21 '10 05:10

Geuis


2 Answers

Use from django.conf import settings but mind that settings is not a module. The documentation clearly explains that and your use case.

like image 93
AndiDog Avatar answered Sep 24 '22 23:09

AndiDog


from django.conf import settings as conf_settings project_path = conf_settings.PROJECT_PATH 
like image 26
Muhammad Taqi Avatar answered Sep 23 '22 23:09

Muhammad Taqi