]> git.openstreetmap.org Git - osqa.git/blob - forum/middleware/custom_pages.py
Merge pull request #1 from udacity/add_requirements_file
[osqa.git] / forum / middleware / custom_pages.py
1 from django.http import Http404
2 from django.conf import settings
3
4 from forum.views.meta import page
5
6 class CustomPagesFallbackMiddleware(object):
7     def process_response(self, request, response):
8         if response.status_code != 404:
9             return response # No need to check for a flatpage for non-404 responses.
10         try:
11             return page(request)
12         # Return the original response if any errors happened. Because this
13         # is a middleware, we can't assume the errors will be caught elsewhere.
14         except Http404:
15             return response
16         except:
17             if settings.DEBUG:
18                 raise
19             return response