forked from django/django
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed django#16774 -- Allow view to raise DoesNotResolve to make URL …
…Resolver to keep searching for a URL.
- Loading branch information
Showing
5 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,12 @@ def get_response(self, request): | |
urlconf = request.urlconf | ||
urlresolvers.set_urlconf(urlconf) | ||
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) | ||
# Use generators and try to resolve matching URL patterns one by | ||
# one | ||
url_patterns = (pattern for pattern in resolver.url_patterns) | ||
resolver = urlresolvers.RegexURLResolver(r'^/', url_patterns) | ||
|
||
while response is None: | ||
callback, callback_args, callback_kwargs = resolver.resolve( | ||
request.path_info) | ||
|
||
|
@@ -110,19 +115,24 @@ def get_response(self, request): | |
if response: | ||
break | ||
|
||
if response is None: | ||
try: | ||
response = callback(request, *callback_args, **callback_kwargs) | ||
except Exception as e: | ||
# If the view raised an exception, run it through exception | ||
# middleware, and if the exception middleware returns a | ||
# response, use that. Otherwise, reraise the exception. | ||
for middleware_method in self._exception_middleware: | ||
response = middleware_method(request, e) | ||
if response: | ||
break | ||
if response is None: | ||
raise | ||
if response is None: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
meric
Author
Owner
|
||
try: | ||
response = callback(request, *callback_args, **callback_kwargs) | ||
except urlresolvers.DoesNotResolve, e: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
# Continue resolve URLs if the view raises | ||
# urlresolvers.DoesNotResolve exception to indicate | ||
# the url pattern does not match. | ||
continue | ||
except Exception as e: | ||
# If the view raised an exception, run it through exception | ||
# middleware, and if the exception middleware returns a | ||
# response, use that. Otherwise, reraise the exception. | ||
for middleware_method in self._exception_middleware: | ||
response = middleware_method(request, e) | ||
if response: | ||
break | ||
if response is None: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
raise | ||
|
||
# Complain if the view returned None (a common error). | ||
if response is None: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 2ef7d14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @charettes!
I've followed your comments and fixed up the code:
I don't think this check is required anymore since you're already breaking at line 115.