Opened 20 years ago
Closed 20 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 |
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?
(In [1296]) Fixed #845 -- flatpages middleware no longer throws 404 exception for DEBUG=True. Thanks, Hugo