获取NoReverMatch错误的sitemap.xml上的Django get_absolute_url

时间:2015-12-30 04:16:11

标签: django sitemap mezzanine

models.py

def get_absolute_url(self):
    return reverse('abc', kwargs={'slug': self.slug})

urls.py

from posts.views import xyz
from posts.sitemaps import PostSitemap


sitemaps = {
    'posts': PostSitemap()
}

urlpatterns = patterns(
    url(r'^posts/(?P<slug>[\w-]+)/$',xyz, name='abc'),
    url(r'^sitemap\.xml$',sitemap, {'sitemaps': sitemaps}),
)

sitemaps.py

class PostSitemap(Sitemap):
    changefreq = 'daily'
    pirority = 0.5

    def items(self):
        return Post.objects.all()

我没有更改默认的contib / sitemaps / templates / sitemap.xml,当我浏览mysite / sitemap.xml时,它会抛出错误:

反向&#39; abc&#39;参数&#39;()&#39;和关键字参数&#39; {&#39; slug&#39 ;: u&#39; my-slug-goes-here&#39;}&#39;未找到。尝试了0种模式:[]

1 个答案:

答案 0 :(得分:0)

class PostSitemap(Sitemap):
    changefreq = 'daily'
    pirority = 0.5

    def items(self):
        return Post.objects.all()

    def location(self, item):
        return item.get_absolute_url()