﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
845	flatpages middleware throws 404 exception instead of returning response	hugo	Adrian Holovaty	"The new middleware for flatpages athrows an exception when a flatpage is not there, instead just returning the 404 response. That leads to weird tracebacks with DEBUG=True, instead of the expected nice formatted 404 page. A fix (against new_admin, but should be identical in trunk):

{{{
Index: contrib/flatpages/middleware.py
===================================================================
--- contrib/flatpages/middleware.py     (revision 1289)
+++ contrib/flatpages/middleware.py     (working copy)
@@ -1,5 +1,6 @@
 from django.contrib.flatpages.views import flatpage
 from django.conf.settings import DEBUG
+from django.core.extensions import Http404
 
 class FlatpageFallbackMiddleware:
     def process_response(self, request, response):
@@ -9,6 +10,8 @@
             return flatpage(request, request.path)
         # Return the original response if any errors happened. Because this
         # is a middleware, we can't assume the errors will be caught elsewhere.
+        except Http404:
+            return response
         except:
             if DEBUG:
                 raise
}}}

The redirects middleware seems already to check for this situation. Actually the flatpages middleware does talk in a comment about exactly this problem, but just doesn't implement it ;-)

BTW: maybe a component ""contributed apps"" would be in order, since flatpages and redirects aren't part of core any more?"	defect	closed	Core (Other)		normal	fixed			Unreviewed	0	0	0	0	0	0
