<commit_before>from django.contrib.flatpages.views import flatpage
from django.conf.settings import DEBUG

class FlatpageFallbackMiddleware:
    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.
        except:
            if DEBUG:
                raise
            return response
<commit_msg>Fixed #845 -- flatpages middleware no longer throws 404 exception for DEBUG=True. Thanks, Hugo<commit_after>from django.contrib.flatpages.views import flatpage
from django.core.extensions import Http404
from django.conf.settings import DEBUG

class FlatpageFallbackMiddleware:
    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.
        except Http404:
            return response
        except:
            if DEBUG:
                raise
            return response

{'fraction_non_alphanumeric': 0.05310344827586207, 'fraction_numerical': 0.016551724137931035, 'mean_word_length': 2.4796163069544366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7043668', 'n_tokens_mistral': 360, 'n_tokens_neox': 337, 'n_words': 142}