本文整理匯總了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
示例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
示例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,
})
示例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>'
示例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
示例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')
示例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}))
示例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)
示例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"])
示例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"])
示例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/")
示例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")
示例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
示例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