网站地图的使用方式由搜索引擎决定。有些只会对网站地图中的内容进行索引,而另一些则会将其用作起点,并基于交叉链接抓取整个网站。
至于包含非生成页面,我们只是创建了django.contrib.sitemaps.Sitemap的子类,并让它读取每行包含一个URL的纯文本文件。喜欢的东西:
class StaticSitemap(Sitemap):
priority = 0.8
lastmod = datetime.datetime.now()
def __init__(self, filename):
self._urls = []
try:
f = open(filename, 'rb')
except:
return
tmp = []
for x in f:
x = re.sub(r"\s*#.*$", '', x) # strip comments
if re.match('^\s*$', x):
continue # ignore blank lines
x = string.strip(x) # clean leading/trailing whitespace
x = re.sub(' ', '%20', x) # convert spaces
if not x.startswith('/'):
x = '/' + x
tmp.append(x)
f.close()
self._urls = tmp
# __init__
def items(self):
return self._urls
def location(self, obj):
return obj
你可以像这样调用它在主站点地图程序:
sitemap['static'] = StaticSitemap(settings.DIR_ROOT +'/sitemap.txt')
而且我们sitemap.txt文件看起来是这样的:
# One URL per line.
# All paths start from root - i.e., with a leading/
# Blank lines are OK.
/tour/
/podcast_archive/
/related_sites/
/survey/
/youtube_videos/
/teachers/
/workshops/
/workshop_listing_info/
/aboutus/
/history/
/investment/
/business/
/contact/
/privacy_policy/
/graphic_specs/
/help_desk/
我我真的很抱歉花了很长时间回复,完全忘了它。我不太喜欢这个解决方案,但它是可以接受的。我自己使用了urlresolver,但它也很混乱。所以我仍然怀疑。 – vshulyak 2010-09-05 19:18:50
不用担心。我不是' – 2010-09-05 23:04:14
我也没有爱上它,但是当我们做到了这一点时(2007年夏),它似乎是一种快速实现它的方法。 – 2010-09-05 23:05:15