Django网站地图 - 双面http://在网址前面 [英] Django sitemap - double http:// in front of URL

查看:118
本文介绍了Django网站地图 - 双面http://在网址前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django 1.4.12中,我有一个Sitemap类:

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

def location(self,obj) $ b return str(obj)

和urls.py

  sitemaps = {
'global':MySitemap,
}

...

urlpatterns = patterns('',
...
url(r'^ sitemap\.xml $','django.contrib.sitemaps.views.sitemap',{'sitemaps':但是,我的生成sitemap.xml有 http:/ p pre

/ http:// 在它的前面,如:

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

导致此问题的原因是什么?

解决方案

你可能已经包括 htt您的网站对象的网站框架中的域名( django.contrib.sites $ C>)。删除它。



此字段应该只包括实际的域名,而不是协议,因为协议本身可以改变(例如,到 https:/ / )。


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?

解决方案

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://).

这篇关于Django网站地图 - 双面http://在网址前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆