Fix fix for file not found
authorMagnus Hagander <magnus@hagander.net>
Mon, 11 Jun 2018 12:13:55 +0000 (14:13 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 11 Jun 2018 12:13:55 +0000 (14:13 +0200)
The old one was broken for URLs with .. in them, the new one was broken
for everything else. Let's see if we can get them both fixed at once.

postgresqleu/static/views.py

index 6de81a28315dfda54e2b6e1f5da5e664c5b4a6f0..d27b48d7b5c15612ea22180f666bec48809250df 100644 (file)
@@ -1,5 +1,5 @@
 from django.http import HttpResponse, Http404
-from django.template import loader
+from django.template import loader, TemplateDoesNotExist
 
 # Fallback handler for URLs not matching anything else. Fall them
 # back to a static template. If that one is not found, send a 404
@@ -9,6 +9,9 @@ def static_fallback(request, url):
        if url.find('..') > -1:
                raise Http404('Page not found')
 
-       t = loader.get_template('pages/%s.html' % url)
-       return HttpResponse(t.render())
+       try:
+               t = loader.get_template('pages/%s.html' % url)
+               return HttpResponse(t.render())
+       except TemplateDoesNotExist:
+               raise Http404('Page not found')