python - Clarification on how to use os.path.dirname with Django -
I am using Django 1.5 and Python 2.7. My project directory is normal:
There is a project folder named Project Folder inside the project folder, there are two other folders: Prosefolder and Prozap
My settings inside ProjFolder, init .py and urls.py.
inside projApp are my models.py, views.py and my static folders that hold my templates. Now, in my settings .py file, I have the following:
SITE_MEDIA_ROOT = os.path.join (os.path.dirname (__ file__), 'projApp /', 'static / ',' Site_media ')
The above lines of code are perfectly fine and this is the following which I have read in the tutorial. However, it should not be
SITE_MEDIA_ROOT = os.path.join (os.path.dirname (__ file__), '../', 'projApp /', 'static /', 'Site_media')
? From my understanding,
os.path.dirname (__ file__)
is the path to the directory that is in the current file, right? Then it will be projFolder because the settings.py is in projFolder. So should I first not go out of the current directory and then enter the projApp folder to get into the stable folder? The line does not have
os.path.dirname (__ file__), 'projApp /', 'static /', 'site_media'
Is not that the Django should be searched
projectfolder / projfolder / projApp / static
? If so, how to find the current settings.py directory without any support without support?
yes it should be :) At least this is how my projects are near, instead Except for ..
this is:
BASE_DIR = os.path.dirname (os. Path.dirname (__ file__))
I think it now comes from default in setings.py.
Are you 100% sure settings.py is where you have it?
It may be that try adding some print statement to the settings and to see the actual values of those paths to run the test path
print os.path .dirname (__file__)
Comments
Post a Comment