class PostDetailView(DetailView):
model = Post
template_name = 'detail.html'
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
instance = Post.objects.get(pk=self.kwargs.get('pk'))
user = instance.post_user
context['comments'] = Comment.objects.filter(comment_post=instance.pk)
context['comments']['profile'] = Profile.objects.get(user=user)
return context
这是我目前的看法。当我使用该代码时,我收到此错误“QuerySet”对象不支持项目分配。我如何正确附加下面的线?
context['comments']['profile'] = Profile.objects.get(user=user)
ABOUTYOU
相关分类