Django

Code

Ticket #845 (closed: fixed)

Opened 3 years ago

Last modified 3 years ago

flatpages middleware throws 404 exception instead of returning response

Reported by: hugo Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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?

Attachments

Change History

11/19/05 22:55:57 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #845 (flatpages middleware throws 404 exception instead of returning response)




Change Properties
Action