Created
June 18, 2018 22:15
-
-
Save rixx/b8d6c73da48b280a65e144918f7f96b7 to your computer and use it in GitHub Desktop.
Delivering static files on fixed URL in Django
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
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