这是我如何为通用视图 object_detail 使用反向的问题?
如果我像下面这样使用它,错误消息将是: NoReverseMatch at /comment/add/ Reverse for '' with arguments '()' and keyword arguments '{}' not found。
在views.py中:
urlresolvers.reverse('django.views.generic.list_detail.object_detail')
return HttpResponseRedirect(resp)
在 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),
)