Created
November 19, 2013 16:39
-
-
Save bensternthal/7548331 to your computer and use it in GitHub Desktop.
Apache Static Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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