Skip to content

Instantly share code, notes, and snippets.

@bensternthal
Created November 19, 2013 16:39
Show Gist options
  • Save bensternthal/7548331 to your computer and use it in GitHub Desktop.
Save bensternthal/7548331 to your computer and use it in GitHub Desktop.
Apache Static Files
from django.conf import settings
from django.conf.urls.defaults import include, patterns
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns <- this!!
from django.http import HttpResponse
from django.shortcuts import render
***
## In DEBUG mode, serve media files through Django.
if settings.DEBUG:
# Remove leading and trailing slashes so the regex matches.
media_url = settings.MEDIA_URL.lstrip('/').rstrip('/')
urlpatterns += patterns('',
(r'^%s/(?P<path>.*)$' % media_url, 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
(r'^404$', handler404),
(r'^500$', handler500),
)
# If using vagrant - this is required for media to be served under Apache.
urlpatterns += staticfiles_urlpatterns()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment