Skip to content

Instantly share code, notes, and snippets.

@adamghill
Created February 2, 2014 01:27
Show Gist options
  • Save adamghill/8761762 to your computer and use it in GitHub Desktop.
Save adamghill/8761762 to your computer and use it in GitHub Desktop.
Serve static files from Django. This is bad for performance and you shouldn't do it and blah, blah, blah.
from os import path
from django.conf import settings
DOCUMENT_ROOT = path.dirname(path.realpath(__file__))
urlpatterns += patterns('',
url(r'^robots\.txt$', 'django.views.static.serve', {
'path': settings.STATIC_URL + 'robots.txt',
'document_root': DOCUMENT_ROOT,
}),
url(r'^favicon\.ico$', 'django.views.static.serve', {
'path': settings.STATIC_URL + 'img/apple-touch-icon.png',
'document_root': DOCUMENT_ROOT,
}),
url(r'(?P<path>^apple-touch-icon(-\d{2,3}x\d{2,3})?(-precomposed)?\.png$)', 'django.views.static.serve', {
'path': settings.STATIC_URL + 'img/apple-touch-icon.png',
'document_root': DOCUMENT_ROOT,
}),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment