Skip to content

Instantly share code, notes, and snippets.

@fxadecimal
Created July 20, 2020 17:38
Show Gist options
  • Save fxadecimal/459d98fc4d1fb708e20a368319645b69 to your computer and use it in GitHub Desktop.
Save fxadecimal/459d98fc4d1fb708e20a368319645b69 to your computer and use it in GitHub Desktop.
Quick workaround for serving static HTML / SPA from django in development
# 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