Dynavera/config/views.py
2026-01-17 14:11:24 +00:00

14 lines
No EOL
533 B
Python

from django.utils._os import safe_join
from django.views.static import serve as static_serve
from django.views.decorators.csrf import ensure_csrf_cookie
import posixpath
from pathlib import Path
@ensure_csrf_cookie
def serve_frontend(request, path, document_root = None):
path = posixpath.normpath(path).lstrip("/")
fullpath = Path(safe_join(document_root, path))
if fullpath.is_file():
return static_serve(request, path, document_root)
else:
return static_serve(request, "index.html", document_root)