PageRenderTime 102ms CodeModel.GetById 61ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/django/contrib/flatpages/middleware.py

https://code.google.com/p/mango-py/
Python | 18 lines | 15 code | 1 blank | 2 comment | 2 complexity | 2aeb74675604648b01ca227399a69436 MD5 | raw file
 1from django.contrib.flatpages.views import flatpage
 2from django.http import Http404
 3from django.conf import settings
 4
 5class FlatpageFallbackMiddleware(object):
 6    def process_response(self, request, response):
 7        if response.status_code != 404:
 8            return response # No need to check for a flatpage for non-404 responses.
 9        try:
10            return flatpage(request, request.path_info)
11        # Return the original response if any errors happened. Because this
12        # is a middleware, we can't assume the errors will be caught elsewhere.
13        except Http404:
14            return response
15        except:
16            if settings.DEBUG:
17                raise
18            return response