views.py 711 B

123456789101112131415161718192021
  1. import re
  2. from django.conf import settings
  3. from django.http import HttpResponse
  4. from django.shortcuts import render
  5. from django.template.loader import render_to_string
  6. async def health(request):
  7. return HttpResponse("ok", content_type="text/plain")
  8. def index(request, *args):
  9. if base_path := settings.FORCE_SCRIPT_NAME:
  10. content = render_to_string(
  11. "index.html", {"base_path": base_path}, request=request
  12. )
  13. # Replace base href (Not easy to add this as a django template var from angular index.html)
  14. content = re.sub(r'<base href="/"/>', f'<base href="/{base_path}/">', content)
  15. return HttpResponse(content)
  16. return render(request, "index.html")