PageRenderTime 17ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/django/contrib/flatpages/middleware.py

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