Question

I am using Django 1.5 and Python 2.7. My project directory is the usual:

There is the project folder called projectFolder. Inside projectFolder, there are two other folders: projFolder and projApp.

Inside projFolder is my settings.py, init.py and urls.py.

Inside projApp is my models.py, views.py and my static folder which holds 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 lines of code above work perfectly fine and this is what I read in the tutorial I was following. However, shouldn't it 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 which the current file is in, correct? So that would be projFolder since settings.py is in projFolder. So shouldn't I back out of the current directory first and then enter the projApp folder in order to get to the static folder? Doesn't the line

os.path.dirname(__file__), 'projApp/', 'static/', 'site_media' 

mean that Django should search

projectFolder/projFolder/projApp/static

? If yes, then how is it finding static without backing out of the current settings.py directory first?

Was it helpful?

Solution

Yes it should :) At leasts that's how my projects have it, except instead of .. there is this:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

I think it comes now in setings.py by default.

Are you 10000% sure that the settings.py is where you say it is?

Maybe try adding some print statements to settings.py and run the test sever, to see real values of those paths

 print os.path.dirname(__file__)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top