=== modified file 'django/core/handlers/base.py'
|
|
|
72 | 72 | try: |
73 | 73 | # Reset the urlconf for this thread. |
74 | 74 | urlresolvers.set_urlconf(None) |
| 75 | # Obtain a default resolver. It's needed early for handling 404's. |
| 76 | resolver = urlresolvers.RegexURLResolver(r'^/', None) |
| 77 | |
| 78 | # Apply request middleware |
| 79 | for middleware_method in self._request_middleware: |
| 80 | response = middleware_method(request) |
| 81 | if response: |
| 82 | return response |
75 | 83 | |
76 | 84 | # Get urlconf from request object, if available. Otherwise use default. |
77 | 85 | urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF) |
78 | | |
79 | 86 | # Set the urlconf for this thread to the one specified above. |
80 | 87 | urlresolvers.set_urlconf(urlconf) |
| 88 | # Reset the resolver with a possibly new urlconf |
81 | 89 | resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) |
82 | 90 | |
83 | | # Apply request middleware |
84 | | for middleware_method in self._request_middleware: |
85 | | response = middleware_method(request) |
86 | | if response: |
87 | | return response |
88 | | |
89 | 91 | callback, callback_args, callback_kwargs = resolver.resolve( |
90 | 92 | request.path_info) |
91 | 93 | |
=== modified file 'tests/regressiontests/middleware_exceptions/tests.py'
|
|
|
8 | 8 | raise Exception('Exception') |
9 | 9 | |
10 | 10 | class MiddlewareExceptionTest(TestCase): |
11 | | def __init__(self, *args, **kwargs): |
12 | | super(MiddlewareExceptionTest, self).__init__(*args, **kwargs) |
| 11 | def setUp(self): |
13 | 12 | self.exceptions = [] |
14 | 13 | got_request_exception.connect(self._on_request_exception) |
15 | | |
16 | | def setUp(self): |
17 | 14 | self.client.handler.load_middleware() |
18 | 15 | |
19 | 16 | def tearDown(self): |
| 17 | got_request_exception.disconnect(self._on_request_exception) |
20 | 18 | self.exceptions = [] |
21 | 19 | |
22 | 20 | def _on_request_exception(self, sender, request, **kwargs): |