2005-11-11 12:45:05 +08:00
|
|
|
from django.contrib.flatpages.views import flatpage
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.http import Http404
|
|
|
|
from django.conf import settings
|
2005-11-11 12:45:05 +08:00
|
|
|
|
2006-06-08 13:00:13 +08:00
|
|
|
class FlatpageFallbackMiddleware(object):
|
2005-11-11 12:45:05 +08:00
|
|
|
def process_response(self, request, response):
|
|
|
|
if response.status_code != 404:
|
|
|
|
return response # No need to check for a flatpage for non-404 responses.
|
|
|
|
try:
|
|
|
|
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.
|
2005-11-20 12:55:57 +08:00
|
|
|
except Http404:
|
|
|
|
return response
|
2005-11-11 12:45:05 +08:00
|
|
|
except:
|
2006-05-02 09:31:56 +08:00
|
|
|
if settings.DEBUG:
|
2005-11-11 12:45:05 +08:00
|
|
|
raise
|
|
|
|
return response
|