Python django.urls.URLResolver() Examples

The following are 6 code examples of django.urls.URLResolver(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.urls , or try the search function .
Example #1
Source File: end_to_end_test.py    From hknweb with MIT License 5 votes vote down vote up
def _get_reversed_urlpatterns(urlpatterns=urlpatterns):
    """Yields a list of all URLs that we can reverse with default args."""
    for urlpattern in urlpatterns:
        if isinstance(urlpattern, URLPattern):
            try:
                path = reverse(urlpattern.name, *urlpattern.default_args)
            except NoReverseMatch:
                pass
            else:
                yield path
        elif isinstance(urlpattern, URLResolver):
            # handle recursive urlpattern definitions
            yield from _get_reversed_urlpatterns(urlpatterns=urlpattern.url_patterns) 
Example #2
Source File: models.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_resolver(cls):
        if '_routablepage_urlresolver' not in cls.__dict__:
            subpage_urls = cls.get_subpage_urls()
            cls._routablepage_urlresolver = URLResolver(RegexPattern(r'^/'), subpage_urls)

        return cls._routablepage_urlresolver 
Example #3
Source File: test_urls_configured.py    From open with MIT License 5 votes vote down vote up
def list_urls(lis, acc=None):
    # ripped from stackoverflow
    if acc is None:
        acc = []
    if not lis:
        return
    data = lis[0]
    if isinstance(data, URLPattern):
        yield acc + [str(data.pattern)]
    elif isinstance(data, URLResolver):
        yield from list_urls(data.url_patterns, acc + [str(data.pattern)])
    yield from list_urls(lis[1:], acc) 
Example #4
Source File: urlresolvers.py    From django-pgschemas with MIT License 5 votes vote down vote up
def tenant_patterns(*urls):
    """
    Add the tenant prefix to every URL pattern within this function.
    This may only be used in the root URLconf, not in an included URLconf.
    """
    return [URLResolver(TenantPrefixPattern(), list(urls))] 
Example #5
Source File: compatibility.py    From wagtail_app_pages with MIT License 5 votes vote down vote up
def get_resolver(url, url_config):
        return URLResolver(RegexPattern(r'^{}'.format(url)), url_config) 
Example #6
Source File: models.py    From Inboxen with GNU Affero General Public License v3.0 5 votes vote down vote up
def route(self, request, path_components):
        if not self.live:
            raise Http404

        resolver = URLResolver(RegexPattern(r"^"), self.APP_PREFIX + self.app)
        path = request.path[len(self.url):]
        view, args, kwargs = resolver.resolve(path)

        self._view = view
        return (self, args, kwargs)