Django static media files are not coming through

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?

Answers


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}),

Need Your Help

Programmatically lock iPhone screen in iOS 7

iphone ios objective-c ios7

I know that we can call GSEventLockDevice (); from the GraphicsServices.framework to lock the screen in iOS 6 and older version, as explained by H2CO3 Here. But unfortunately it's not working in iO...

SVG features supported in iOS

ios html5 svg

I can't seem to find a good list of SVG features supported in iOS, the best I got is this: