views:

34

answers:

1

I cannot, for the life of me, get my static media files to come through on my local test machine in one particular project, though I've had no problem with a few other Django projects.

I'm using Django 1.1.1 and a Windows XP environment.

My settings.py looks like this for the media-hosting stuff:

ROOT_PATH = os.path.dirname(__file__)
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(ROOT_PATH, 'site_media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/site_media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

And it's looking in here:

http://127.0.0.1:8000/site_media/schedule/img/add.png

And the file is in the site directory along the lines of this:

c:\django\project_file\site_media\schedule\img\add.png

But for some reason the image still ain't showing up.

Any advice?

+3  A: 

Your media root should be fully specified; define your MEDIA_ROOT as follows.

ROOT_PATH = os.path.dirname(__file__)
MEDIA_ROOT = os.path.join(ROOT_PATH, 'site_media')

Did you read this documentation about static files; you should also add extra route configuration to your urls.py to make sure that requests to the static content are handled correctly.

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT}),
Thomas
Thanks, that fixed it up and ended days of frustration. I'll be given that particular doc page a more thorough reading tonight.
Michael Morisy
Please mark as answer if it helped you.
Thomas