summaryrefslogtreecommitdiff
path: root/django/contrib/sitemaps/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/sitemaps/__init__.py')
-rw-r--r--django/contrib/sitemaps/__init__.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
index 8f984ae3dc..bd1139ff70 100644
--- a/django/contrib/sitemaps/__init__.py
+++ b/django/contrib/sitemaps/__init__.py
@@ -1,4 +1,3 @@
-from contextlib import suppress
from urllib.parse import urlencode
from urllib.request import urlopen
@@ -37,9 +36,11 @@ def _get_sitemap_full_url(sitemap_url):
# First, try to get the "index" sitemap URL.
sitemap_url = reverse('django.contrib.sitemaps.views.index')
except NoReverseMatch:
- with suppress(NoReverseMatch):
+ try:
# Next, try for the "global" sitemap URL.
sitemap_url = reverse('django.contrib.sitemaps.views.sitemap')
+ except NoReverseMatch:
+ pass
if sitemap_url is None:
raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")
@@ -88,8 +89,10 @@ class Sitemap:
if site is None:
if django_apps.is_installed('django.contrib.sites'):
Site = django_apps.get_model('sites.Site')
- with suppress(Site.DoesNotExist):
+ try:
site = Site.objects.get_current()
+ except Site.DoesNotExist:
+ pass
if site is None:
raise ImproperlyConfigured(
"To use sitemaps, either enable the sites framework or pass "