Created
July 20, 2020 17:38
-
-
Save fxadecimal/459d98fc4d1fb708e20a368319645b69 to your computer and use it in GitHub Desktop.
Quick workaround for serving static HTML / SPA from django in development
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
# app/urls.py | |
urlpatterns += [ | |
path('<path:path>', views.view_static, name='serve') | |
] | |
# app/views.py | |
from django.views.static import serve | |
def view_static(response, path): | |
path = os.path.join('static', path) | |
return serve(response, os.path.basename(path), os.path.dirname(path)) | |
# can now serve static/app.js at | |
# http://localhost:8000/app.js | |
# For a more comprehensive solution check out django-spa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment