Opened 14 years ago

Closed 14 years ago

#845 closed defect (fixed)

flatpages middleware throws 404 exception instead of returning response

Reported by: hugo Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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/
--- contrib/flatpages/     (revision 1289)
+++ contrib/flatpages/     (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
             if DEBUG:

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?

Change History (1)

comment:1 Changed 14 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [1296]) Fixed #845 -- flatpages middleware no longer throws 404 exception for DEBUG=True. Thanks, Hugo

Note: See TracTickets for help on using tickets.
Back to Top