Django reverse() and CBV

I know I'm doing something stupid here, but I can't seem to find it (must be teh stupid).

In urls.py I have:

urlpatterns=patterns(...
    ...
    url(r'(?P<cat>[-w]*)/(?P<slug>[-w]+)/$', PlantDetailView.as_view(), name='detail-view'),
    ....
    )

And in the template I have:

{%  url 'detail-view' cat=category_slug slug=plant.slug %}

But I get the following NoReverseMatch error:

Reverse for 'detail-view' with arguments '()' and keyword arguments '{u'slug': u'foo', u'cat': u'bar'}' not found.

I've tried using *args and **kwargs , but no luck.

Thanks for helping!


Sorry, it was a namespace issue.

Since the 'plants' urls are included in the main urls.py, the solution is:

{%  url 'plants:detail_view' cat=category_slug slug=plant.slug %}

I'm sure that Samuele Mattiuzzo would have caught it had I said that the url file was plants/urls.py but I left out that important detail.

Thanks for your help, anyway.

链接地址: http://www.djcxy.com/p/77266.html

上一篇: 转换data.table中的列类

下一篇: Django reverse()和CBV