NoReverseMatch at /sitemap.xml with named groups url



访问www.example.com/sitemap.xml返回以下错误:

reverse for 'netherland' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

我有以下url

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)

你可以给URL配置一个名字,比如:

url(r'^(?P<country>netherland|germany|spain)/$', FeedList.as_view(), name="country")

,然后将站点地图中的位置改为:

def location(self, item):
    return reverse("country", kwargs={"country": item}

或类似于你的逻辑

最新更新