当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.NoReverseMatch方法代码示例

本文整理汇总了Python中django.urls.exceptions.NoReverseMatch方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NoReverseMatch方法的具体用法?Python exceptions.NoReverseMatch怎么用?Python exceptions.NoReverseMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.urls.exceptions的用法示例。


在下文中一共展示了exceptions.NoReverseMatch方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: label_and_url_for_value

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def label_and_url_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.model._default_manager.using(self.db).get(**{key: value})
        except (ValueError, self.rel.model.DoesNotExist):
            return '', ''

        try:
            url = reverse(
                '%s:%s_%s_change' % (
                    self.admin_site.name,
                    obj._meta.app_label,
                    obj._meta.object_name.lower(),
                ),
                args=(obj.pk,)
            )
        except NoReverseMatch:
            url = ''  # Admin not registered for target model.

        return Truncator(obj).words(14, truncate='...'), url 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:22,代码来源:widgets.py

示例2: label_and_url_for_value

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def label_and_url_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.model._default_manager.using(self.db).get(**{key: value})
        except (ValueError, self.rel.model.DoesNotExist, ValidationError):
            return '', ''

        try:
            url = reverse(
                '%s:%s_%s_change' % (
                    self.admin_site.name,
                    obj._meta.app_label,
                    obj._meta.object_name.lower(),
                ),
                args=(obj.pk,)
            )
        except NoReverseMatch:
            url = ''  # Admin not registered for target model.

        return Truncator(obj).words(14, truncate='...'), url 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:22,代码来源:widgets.py

示例3: whoami

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def whoami(request):
    if settings.HOOVER_AUTHPROXY:
        logout_url = '/__auth/logout'
    else:
        logout_url = reverse('logout') + '?next=/'

    urls = {
        'login': settings.LOGIN_URL,
        'admin': reverse('admin:index'),
        'logout': logout_url,
        'hypothesis_embed': settings.HOOVER_HYPOTHESIS_EMBED,
    }
    try:
        password_change = reverse('password_change')
    except NoReverseMatch:
        pass
    else:
        urls['password_change'] = password_change
    return JsonResponse({
        'username': request.user.username,
        'admin': request.user.is_superuser,
        'urls': urls,
        'title': settings.HOOVER_TITLE,
    }) 
开发者ID:liquidinvestigations,项目名称:hoover-search,代码行数:26,代码来源:views.py

示例4: sub_match_reply

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def sub_match_reply(match):
    username = match.group()[1:]
    try:
        url = reverse("User:user", kwargs={"slug": username})
    except NoReverseMatch:
        url = username
    return '<a href="' + url + '">@' + username + '</a>' 
开发者ID:Arianxx,项目名称:BookForum,代码行数:9,代码来源:discussion_tags.py

示例5: to_representation

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def to_representation(self, page):
        try:
            return page.full_url
        except NoReverseMatch:
            return None 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:serializers.py

示例6: test_reverse_overridden_name_default_doesnt_work

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_reverse_overridden_name_default_doesnt_work(self):
        with self.assertRaises(NoReverseMatch):
            self.routable_page.reverse_subpage('override_name_test') 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:tests.py

示例7: test_pageurl_fallback_without_valid_fallback

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_pageurl_fallback_without_valid_fallback(self):
        tpl = template.Template('''{% load wagtailcore_tags %}<a href="{% pageurl page fallback='not-existing-endpoint' %}">Fallback</a>''')
        with self.assertRaises(NoReverseMatch):
            tpl.render(template.Context({'page': None})) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:tests.py

示例8: test_urls

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_urls(self):
        for name in list_names():
            try:
                reverse(name)
            except NoReverseMatch:
                continue
            self.compare(name) 
开发者ID:iguana-project,项目名称:iguana,代码行数:9,代码来源:test_i18n.py

示例9: test_urls_for_main_error

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_urls_for_main_error(self):
        with self.assertRaises(NoReverseMatch):
            management.call_command("reverse_url", "entries", schemas=["www"]) 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:5,代码来源:test_external_url_resolution.py

示例10: test_urls_for_blog_error

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_urls_for_blog_error(self):
        with self.assertRaises(NoReverseMatch):
            management.call_command("reverse_url", "register", schemas=["blog"]) 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:5,代码来源:test_external_url_resolution.py

示例11: test_reverse

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_reverse(self):
        page = models.AppPage.objects.get()

        self.assertEqual(page.reverse("tickets-index"), "/")

        with self.assertRaises(NoReverseMatch):
            # url name not preset in tickets.urls
            page.reverse("stats")

        self.assertEqual(page.reverse("tickets-detail", kwargs={"pk": 12}), "/ticket/12/") 
开发者ID:Inboxen,项目名称:Inboxen,代码行数:12,代码来源:test_models.py

示例12: test_bad_viewname

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def test_bad_viewname(self):
        with self.assertRaises(NoReverseMatch):
            app_reverse(self.page, "noop") 
开发者ID:Inboxen,项目名称:Inboxen,代码行数:5,代码来源:test_utils.py

示例13: _get_global_context

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def _get_global_context(request):
    """
    Returns a dictionary of context data shared by the views
    """
    context = {}

    # Returns the reverse lookup URL of the provided view with
    # the provided slug argument. Returns None if the view is
    # not accessible under the current configuration
    def get_reversed_url_or_none(view_name, slug):
        try:
            return reverse('uniauth:%s' % view_name, args=[slug])
        except NoReverseMatch:
            return None

    # Add a list of Institution tuples, with each containing:
    # (name, slug, CAS login url, Profile link URL)
    institutions = Institution.objects.all()
    institutions = list(map(lambda x: (x.name, x.slug,
            get_reversed_url_or_none("cas-login", x.slug),
            get_reversed_url_or_none("link-from-profile", x.slug)),
            institutions))
    context['institutions'] = institutions

    # Add the query parameters, as a string
    query_params = urlencode(request.GET)
    prefix = '?' if query_params else ''
    context['query_params'] = prefix + query_params

    return context 
开发者ID:lgoodridge,项目名称:django-uniauth,代码行数:32,代码来源:views.py

示例14: is_navigation

# 需要导入模块: from django.urls import exceptions [as 别名]
# 或者: from django.urls.exceptions import NoReverseMatch [as 别名]
def is_navigation(self):
        if not hasattr(self, "_is_navigation"):
            self._is_navigation = False
            try:
                if self.method == "GET" and (
                    self.view.action == "list" or not hasattr(self.view, "list")
                ):
                    self.view.reverse_action("list")
                    self._is_navigation = True
            except NoReverseMatch:
                pass

        return self._is_navigation 
开发者ID:5monkeys,项目名称:django-bananas,代码行数:15,代码来源:yasg.py


注:本文中的django.urls.exceptions.NoReverseMatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。