From 2381e2cf9bdf179102ede560a7bb88380dff1953 Mon Sep 17 00:00:00 2001 From: aranega Date: Tue, 13 Aug 2024 10:13:10 -0600 Subject: [PATCH] Fix recursive loop in local dev for unknown urls --- applications/visualizer/backend/visualizer/views.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/applications/visualizer/backend/visualizer/views.py b/applications/visualizer/backend/visualizer/views.py index 66508a13..3e65b6ef 100644 --- a/applications/visualizer/backend/visualizer/views.py +++ b/applications/visualizer/backend/visualizer/views.py @@ -3,7 +3,7 @@ from pathlib import Path from django.conf import settings -from django.http import FileResponse, HttpResponseRedirect +from django.http import FileResponse, HttpResponseRedirect, Http404, HttpResponse from django.shortcuts import redirect from django.urls import reverse from django.utils._os import safe_join @@ -15,7 +15,7 @@ def view_404(request, exception=None): return HttpResponseRedirect(reverse("index")) -def index(request, path=""): +def index(request, path="", already_asked=False): if path == "": path = "index.html" fullpath = Path(safe_join(settings.STATIC_ROOT, "www", path)) @@ -24,15 +24,18 @@ def index(request, path=""): try: fullpath.open("rb") except FileNotFoundError: - return index(request, "") # index.html + if already_asked: + # This is here to avoid recursive loop in local dev + return HttpResponse(content=f"Page {path} cannot be found :(", status=404) + return index(request, "", already_asked=True) # index.html return FileResponse(fullpath.open("rb"), content_type=content_type) -TILE_SIZE = 512 +TILE_SIZE = 512 # Should be computed BLACK_TILE = Image.new("RGB", (TILE_SIZE, TILE_SIZE)) BLACK_TILE_BUFFER = io.BytesIO() BLACK_TILE.save(BLACK_TILE_BUFFER, format="JPEG") -MAX_ZOOM = 6 +MAX_ZOOM = 6 # Should be set def get_tile(request, slice, x, y, zoom):