Đây là câu hỏi làm thế nào để tôi sử dụng ngược lại cho đối tượng generic view_detail?Làm cách nào để nhận URL ngược lại cho chế độ xem chung?
Nếu tôi sử dụng nó như sau, thông báo lỗi sẽ là: NoReverseMatch at/comment/add/ Đảo ngược với '' bằng đối số '()' và đối số từ khóa '{}' không tìm thấy.
trong views.py:
urlresolvers.reverse('django.views.generic.list_detail.object_detail')
return HttpResponseRedirect(resp)
trong 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),
)
Câu trả lời này cho biết bản chất của vấn đề, nó tốt hơn. – dspjm