Skip to content

Instantly share code, notes, and snippets.

@dnoyes
Created January 21, 2012 17:23
Show Gist options
  • Save dnoyes/1653345 to your computer and use it in GitHub Desktop.
Save dnoyes/1653345 to your computer and use it in GitHub Desktop.
serving uploaded MEDIA
# settings.py
import os
VENV_ROOT = os.environ.get('VIRTUAL_ENV', '')
MEDIA_ROOT = VENV_ROOT + '/media/'
MEDIA_URL = '/media/'
# urls.py
urlpatterns = patterns('',
# ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
@dnoyes
Copy link
Author

dnoyes commented Jan 21, 2012

While running in an activated virtualenv, I hit:

http://localhost:8000/media/teams/awesome-pants.jpg

And I get a 404. awesome-pants.jpg was uploaded successfully via the django admin.

@dnoyes
Copy link
Author

dnoyes commented Jan 21, 2012

Neeeeeever mind. I made the media pattern FIRST and all is well.

urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += ( ... )

@sleekslush
Copy link

Cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment