如何get_context_data从CVB DetailView中获取'pk'或'id' ?
class MyDetail(DetailView):
model = Book
template_name = 'book.html'
def get_context_data(self, **kwargs):
context = super(MyDetail, self).get_context_data(**kwargs)
context['something'] = Book.objects.filter(pk=pk)
return context
Run Code Online (Sandbox Code Playgroud)
网址:
url(r'^book/(?P<pk>\d+)/$', MyDetail.as_view(), name='book'),
Run Code Online (Sandbox Code Playgroud)