我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.core.urlresolvers.LocaleRegexURLResolver()。
def i18n_patterns(prefix, *args): """ Adds the language code prefix to every URL pattern within this function. This may only be used in the root URLconf, not in an included URLconf. """ if isinstance(prefix, six.string_types): warnings.warn( "Calling i18n_patterns() with the `prefix` argument and with tuples " "instead of django.conf.urls.url() instances is deprecated and " "will no longer work in Django 1.10. Use a list of " "django.conf.urls.url() instances instead.", RemovedInDjango110Warning, stacklevel=2 ) pattern_list = patterns(prefix, *args) else: pattern_list = [prefix] + list(args) if not settings.USE_I18N: return pattern_list return [LocaleRegexURLResolver(pattern_list)]
def i18n_patterns(prefix, *args): """ Adds the language code prefix to every URL pattern within this function. This may only be used in the root URLconf, not in an included URLconf. """ if isinstance(prefix, six.string_types): warnings.warn( "Calling i18n_patterns() with the `prefix` argument and with tuples " "instead of django.conf.urls.url() instances is deprecated and " "will no longer work in Django 2.0. Use a list of " "django.conf.urls.url() instances instead.", RemovedInDjango20Warning, stacklevel=2 ) pattern_list = patterns(prefix, *args) else: pattern_list = [prefix] + list(args) if not settings.USE_I18N: return pattern_list return [LocaleRegexURLResolver(pattern_list)]
def is_language_prefix_patterns_used(): """ Returns `True` if the `LocaleRegexURLResolver` is used at root level of the urlpatterns, else it returns `False`. """ return any(isinstance(url_pattern, LocaleRegexURLResolver) for url_pattern in get_resolver(None).url_patterns)