Skip to content

Instantly share code, notes, and snippets.

@rixx rixx/
Created Jun 18, 2018

What would you like to do?
Delivering static files on fixed URL in Django
import os
from django.http import Http404, FileResponse
def get_static(request, path, content_type):
path = os.path.join(settings.BASE_DIR, 'pretalx/static', path)
if not os.path.exists(path):
raise Http404()
return FileResponse(open(path, 'rb'), content_type=content_type)
urlpatterns = [
url('^sw.js', get_static, {'path': 'agenda/js/serviceworker.js', 'content_type': 'application/javascript'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.