Django sitemap - double http:// in front of URL

半世苍凉 提交于 2019-12-13 04:56:50

问题


In Django 1.4.12, I have a Sitemap class:

class MySitemap(Sitemap):
    def items(self):
        return ['/my/url1/',
                '/my/url2/',]

    def location(self, obj):
        return str(obj)

and in urls.py

sitemaps = {
            'global': MySitemap,
            }

...

urlpatterns = patterns('',
...
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),

However, my generate sitemap.xml has http://http:// in front of it, such as:

...
<url><loc>http://http://mywebsite.com/my/url1</loc></url>
...

What is causing this problem?


回答1:


You have probably included http:// in your Site object's domain name from the sites framework (django.contrib.sites). Remove it.

This field should only include the actual domain name, not the protocol, as the protocol itself can change (e.g. to https://).



来源:https://stackoverflow.com/questions/23790009/django-sitemap-double-http-in-front-of-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!