當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。