Serve SPA (Single Page Application) in django using whitenoise
You can install the package via pip:
pip install whitenoise-spa
- Edit your
settings.py
file and addwhitenoise_spa.middleware.WhiteNoiseSPAMiddleware
to the MIDDLEWARE list. The middleware should be placed directly after the Django SecurityMiddleware (if you are using it) and before all other middleware. This middleware replaces the whitenoise middleware.MIDDLEWARE = [ # ... "django.middleware.security.SecurityMiddleware", "whitenoise_spa.middleware.WhiteNoiseSPAMiddleware", # ... ]
- Configure SPA root and urls.
WHITENOISE_SPA_ROOT = BASE_DIR / "dist" WHITENOISE_SPA_URLS = ["/", "/login/", "/settings/"]
- Does not support wildcard urls for SPA urls.
This project is licensed under the terms of the MIT license.