来自django.core.urlresolvers导入反向返回NO url链接

时间:2015-04-28 07:15:35

标签: python django

在我的urls.py中,我已将网址定义为

url(r'^deals/(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>.*)/$','deals.views.deal_detail', name="deal_detail"),

当我尝试使用'get_absolute_url'时如下

def get_absolute_url(self):
    return '/deals/%s/%s/%s/' %(self.pub_date.strftime("%Y"),
        self.pub_date.strftime("%m"),
        self.slug)

这对我来说很好,但是当我使用

from django.core.urlresolvers import reverse
def get_absolute_url(self):
    year = self.pub_date.strftime("%Y")
    month = self.pub_date.strftime("%m")
    slug = self.slug
    return reverse('deal_detail', arg=[year,month,slug])

它不返回href标记的url。任何建议/帮助请

1 个答案:

答案 0 :(得分:0)

这是一个错字。应该是&#39; args&#39;不是&#39; arg。

return reverse('deal_detail', args=[year,month,slug])