views:

26

answers:

2

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?

A: 

Add in the imports section of the view.py file something like "import module_name.settings as settings". Then you can use settings.PROJECT_PATH.

Seitaridis
Are there any security issues with this?
Geuis
The question is on Django, and as apps can be in virtually any directory hierarchy, you don't know from where to import the settings (maybe `from .. import settings` but not necessarily). Django actually provides its own way for doing that, see my answer.
AndiDog
Take a look at http://stackoverflow.com/questions/3430451/using-django-settings-in-templates. Maybe you will find it useful.
Seitaridis
+2  A: 

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

AndiDog