访问www.example.com/sitemap.xml,返回以下错误:
reverse for 'netherland' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我有以下网址
url(r'^(?P<country>netherland|germany|spain)/$', FeedList.as_view()),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
这是我的sitemaps.py
from django.contrib import sitemaps
from django.core.urlresolvers import reverse
class StaticViewSitemap(sitemaps.Sitemap):
priority = 0.5
changefreq = 'daily'
def items(self):
return ['netherland', 'germany', 'spain']
def location(self, item):
return reverse(item)
答案 0 :(得分:0)
您可以为URL配置命名,例如:
url(r'^(?P<country>netherland|germany|spain)/$', FeedList.as_view(), name="country")
然后将站点地图中的位置构建为:
def location(self, item):
return reverse("country", kwargs={"country": item}
或类似于你的逻辑。