tags:

views:

1049

answers:

1

Here is the question how do I use reverse for the generic view object_detail?

If I use it like the following, the error message will be: NoReverseMatch at /comment/add/ Reverse for '' with arguments '()' and keyword arguments '{}' not found.

in views.py:

urlresolvers.reverse('django.views.generic.list_detail.object_detail')
              return HttpResponseRedirect(resp)

in urls.py

common_info_dict = {
    'extra_context':{
         'blogtitle':"Thinking",
         'blogsubtitle':"- blog system",
         'articles_count':Entry.objects.count,
         'comments_count': 0,
         'visitors_count' : 0,
         'category_list':Category.objects.all,
         'tag_list':Tag.objects.all,
         'comment_form': CommentForm,
    },
}

object_detail_info_dict = {
    'queryset': Entry.objects.all(),
    'slug_field': 'slug',
    'template_object_name': 'post',
}

object_detail_info_dict.update(common_info_dict)

    urlpatterns += patterns('django.views.generic.list_detail',
       (r'^posts/(?P<slug>[-\w]+)/$', 'object_detail', object_detail_info_dict),
    )
+10  A: 

The only way to use reverse with generic views - named urls config.

urlpatterns += patterns('django.views.generic.list_detail',
  (r'^posts/(?P<slug>[-\w]+)/$', 'object_detail',
                          object_detail_info_dict, 'post_detail'),
)

reverse('post_detail', args=('foobar',))
Alex Koshelev