Ticket #12950: reverse_namespaced_url.patch

File reverse_namespaced_url.patch, 1.1 KB (added by ungenio, 4 years ago)

Fix parsing url regex patterns when including namespaced urls.

  • django/core/urlresolvers.py

     
    360360        path = parts[1:]
    361361
    362362        resolved_path = []
     363        ns_pattern = ''
    363364        while path:
    364365            ns = path.pop()
    365366
     
    380381            try:
    381382                extra, resolver = resolver.namespace_dict[ns]
    382383                resolved_path.append(ns)
    383                 prefix = prefix + extra
     384                ns_pattern = ns_pattern + extra
    384385            except KeyError, key:
    385386                if resolved_path:
    386387                    raise NoReverseMatch("%s is not a registered namespace inside '%s'" % (key, ':'.join(resolved_path)))
    387388                else:
    388389                    raise NoReverseMatch("%s is not a registered namespace" % key)
    389390
     391        if ns_pattern:
     392            resolver = RegexURLResolver(ns_pattern, resolver.url_patterns)
     393            resolver = RegexURLResolver(r'^/', [resolver])
     394
    390395    return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view,
    391396            *args, **kwargs)))
    392397
Back to Top