Re: #16774 Backtracking URL resolver

118 views
Skip to first unread message

meric

unread,
Sep 13, 2012, 6:31:14 AM9/13/12
to django-d...@googlegroups.com
Thank you charettes looking at my code and giving comments:


I have followed the comments and cleaned up the code:

https://github.com/meric/django/commit/e118337293a480dfff08b9861c7045ac9fc893d5

On Thursday, September 13, 2012 12:01:38 PM UTC+10, meric wrote:
Hi,

I looked at https://code.djangoproject.com/ticket/16774 and decided to implement the feature where views can raise urlresolvers.DoesNotResolve to make URL Resolver to keep searching for a URL. 


It introduces a new Exception class and adds a loop to the BaseHandler.get_response.

Can a committer or developer look at it? It's quite different to the previous patch looked upon favourably by a core developer 10 months ago.

Thanks,
Eric


meric

unread,
Sep 17, 2012, 8:27:08 PM9/17/12
to django-d...@googlegroups.com
The ticket page is here: https://code.djangoproject.com/ticket/16774

I previously said people trying to resolve URLs in their code may have difficulty because the DoesNotResolve exception is not raised until the view is run. Just now I thought how it would be done. I think changing resolver.url_patterns to return an iterator to a generator maybe the way to go?

resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
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)
  try:
      response = callback(request, *callback_args, **callback_kwargs)
  except urlresolvers.DoesNotResolve:
      # Continue resolve URLs if the view raises 
      # urlresolvers.DoesNotResolve exception to indicate
      # the url pattern does not match.
      continue
Reply all
Reply to author
Forward
0 new messages