Django 站点地图间歇性 www

发布于 2024-09-03 19:32:45 字数 1416 浏览 6 评论 0原文

我的 Django 站点的自动站点地图在 url 中包含 www 和将其排除之间波动(我的目标是始终包含它)。这会导致谷歌无法正确索引我的页面,因此我正在尝试缩小导致此问题的范围。

我已设置 PREPEND_WWW = True 并且站点框架中的站点记录设置为包含 www,例如设置为 www.example.com 而不是 example .com。我正在使用 memcached,但页面应该在 48 小时后从缓存中过期,所以我不会想到这会导致问题?

您可以在 http://www.livingspaceltd.co.uk/sitemap 中查看实际存在的问题。 xml(刷新页面几次)。

我的站点地图设置相当平淡,所以我怀疑这就是问题所在,但如果有明显的问题,我缺少以下代码:

***urls.py***

sitemaps = {
    'subpages': Subpages_Sitemap,
    'standalone_pages': Standalone_Sitemap,
    'categories': Categories_Sitemap,
}

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

***sitemaps.py***

# -*- coding: utf-8 -*- 
from django_ls.livingspace.models import Page, Category, Standalone_Page, Subpage
from django.contrib.sitemaps import Sitemap

class Subpages_Sitemap(Sitemap):
    changefreq = "monthly"
    priority = 0.4
    def items(self):
        return Subpage.objects.filter(restricted_to__isnull=True)

class Standalone_Sitemap(Sitemap):
    changefreq = "weekly"
    priority = 1
    def items(self):
        return Standalone_Page.objects.all()

class Categories_Sitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.7
    def items(self):
        return Category.objects.all()

The automatic sitemap for my Django site fluctuates between including the www on urls and leaving it out (I'm aiming to have it in all the time). This has ramifications in google not indexing my pages properly so I'm trying to narrow down what would be causing this issue.

I have set PREPEND_WWW = True and my site record in the sites framework is set to include the www e.g. it's set to www.example.com as opposed to example.com. I'm using memcached but pages should expire from the cache after 48 hours so I wouldn't have thought that would be causing the issue?

You can see the problem in effect at http://www.livingspaceltd.co.uk/sitemap.xml (refresh the page a few times).

My sitemaps setup is fairly prosaic so I'm doubtful that that is the issue, but in case it's something obvious I'm missing here's the code:

***urls.py***

sitemaps = {
    'subpages': Subpages_Sitemap,
    'standalone_pages': Standalone_Sitemap,
    'categories': Categories_Sitemap,
}

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

***sitemaps.py***

# -*- coding: utf-8 -*- 
from django_ls.livingspace.models import Page, Category, Standalone_Page, Subpage
from django.contrib.sitemaps import Sitemap

class Subpages_Sitemap(Sitemap):
    changefreq = "monthly"
    priority = 0.4
    def items(self):
        return Subpage.objects.filter(restricted_to__isnull=True)

class Standalone_Sitemap(Sitemap):
    changefreq = "weekly"
    priority = 1
    def items(self):
        return Standalone_Page.objects.all()

class Categories_Sitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.7
    def items(self):
        return Category.objects.all()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

皓月长歌 2024-09-10 19:32:45

settings.py 中的 PREPEND_WWW = True 必须出现在缓存变量设置之上。这解决了我的问题,与你的问题完全相同。当我在谷歌网站管理员工具中提交站点地图时,我遇到了同样的问题。

PREPEND_WWW = True in settings.py must appear above your caching variable settings. This fixed my problem which is just the same with yours. I ran into this same problem when i submit my sitemap in google webmaster tool.

眼前雾蒙蒙 2024-09-10 19:32:45

这可能是我见过的最奇怪的问题之一。但问题是 Django 在站点地图中构造 URL 的方式非常简单。它只是从数据库获取当前的 Site 对象,并将“domain”字段的值附加到页面的相对位置:

current_site = Site.objects.get_current()
...
loc = "http://%s%s" % (current_site.domain, self.__get('location', item))

(source)

你确定你没有在数据库级别做任何奇怪的事情吗?如果您有多个镜像数据库,但它们不一致,则可能会产生类似的效果。尝试设置一个仅显示 Site.objects.get_current() 的测试视图。大概也会有波动。

如果您使用任何第三方缓存应用程序(例如 Johnny Cache),请尝试将其关闭。

另外,请确保您没有两个 Site 对象 - 一个带 www,一个不带 www(它不应该给您带来类似的效果,但具有多个服务器实例,为不同的 SITE_ID 配置......也许?)

It might be one of the weirdest problem I've seen. But the thing is the way Django constructs URLs in sitemap is extremely straightforward. It just gets curent Site object from the database and appends value of the "domain" field to page's relative location:

current_site = Site.objects.get_current()
...
loc = "http://%s%s" % (current_site.domain, self.__get('location', item))

(source)

Are you sure you are not doing anything weird on a database level? If you had multiple mirrored databases, but they weren't consistant it could produce a similar effect. Try setting up a test view that just displays Site.objects.get_current(). It will probably fluctuate as well.

If you use any third-party caching app (like Johnny Cache) try turning it off.

Also, make sure you don't have two Site objects - one with, and one without www (it shouldn't give you a similar effect, but with multiple server instances, configured for different SITE_ID's... maybe?)

铜锣湾横着走 2024-09-10 19:32:45

好吧,看起来这毕竟是一个缓存错误 - 我不太确定出了什么问题,因为我在一周前进行了更改,所以它的行为肯定不正确,我不得不尝试几个不同的方法来重新启动它。所以这需要一些更深入的调查,但现在正在发挥作用。

Well, it look like it was a caching error after all - I'm not quite sure wht was wrong, as I had made the changes over a week ago, so it defintely wasn't behaving right and I had to try a couple of diffrent methods to restart it. So that bears some deeper investigation, but it's working now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文