#3048: sitemaps and prepend_www -----------------------------------+---------------------------------------- Reporter: simonbun | Owner: adrian Status: reopened | Milestone: Component: Contrib apps | Version: Resolution: | Keywords: sitemaps Stage: Unreviewed | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | -----------------------------------+---------------------------------------- Changes (by niksite):
* status: closed => reopened * resolution: invalid => Comment: I have same issue now. I cannot use www in current_site.domain (I have used this variable in many places) and google webmaster tools reject all addr in sitemap because lack of 'www'. Why we cannot have something like: {{{ --- django_old/contrib/sitemaps/__init__.py 2008-11-19 08:44:26.000000000 +0300 +++ django_new/contrib/sitemaps/__init__.py 2010-11-24 18:57:34.000000000 +0300 @@ -1,4 +1,5 @@ from django.core import urlresolvers, paginator +from django.conf import settings import urllib PING_URL = "http://www.google.com/webmasters/tools/ping" @@ -29,7 +30,10 @@ from django.contrib.sites.models import Site current_site = Site.objects.get_current() - url = "http://%s%s" % (current_site.domain, sitemap_url) + domain = current_site.domain + if settings.PREPEND_WWW and not domain.startswith('www.'): + domain = 'www.' + domain + url = "http://%s%s" % (domain, sitemap_url) params = urllib.urlencode({'sitemap':url}) urllib.urlopen("%s?%s" % (ping_url, params)) @@ -62,9 +66,12 @@ def get_urls(self, page=1): from django.contrib.sites.models import Site current_site = Site.objects.get_current() + domain = current_site.domain + if settings.PREPEND_WWW and not domain.startswith('www.'): + domain = 'www.' + domain urls = [] for item in self.paginator.page(page).object_list: - loc = "http://%s%s" % (current_site.domain, self.__get('location', item)) + loc = "http://%s%s" % (domain, self.__get('location', item)) url_info = { 'location': loc, 'lastmod': self.__get('lastmod', item, None), }}} and {{{ --- django_old/contrib/sitemaps/views.py 2008-11-19 08:44:26.000000000 +0300 +++ django_new/contrib/sitemaps/views.py 2010-11-24 18:57:58.000000000 +0300 @@ -4,6 +4,8 @@ from django.core import urlresolvers from django.utils.encoding import smart_str from django.core.paginator import EmptyPage, PageNotAnInteger +from django.conf import settings + def index(request, sitemaps): current_site = Site.objects.get_current() @@ -15,10 +17,13 @@ else: pages = site.paginator.num_pages sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap', kwargs={'section': section}) - sites.append('%s://%s%s' % (protocol, current_site.domain, sitemap_url)) + domain = current_site.domain + if settings.PREPEND_WWW and not domain.startswith('www.'): + domain = 'www.' + domain + sites.append('%s://%s%s' % (protocol, domain, sitemap_url)) if pages > 1: for page in range(2, pages+1): - sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page)) + sites.append('%s://%s%s?p=%s' % (protocol, domain, sitemap_url, page)) xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites}) return HttpResponse(xml, mimetype='application/xml') }}} This fix works well for me, but it will be great to have this into official django repo. -- Ticket URL: <http://code.djangoproject.com/ticket/3048#comment:6> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.