def comment_block(target): return { 'target': target, 'comment_form': CommentForm(), 'comment_list': Comment.get_by_target(target), 'comment_count': Comment.get_by_target(target).count() }
def comment_block(target): """自定义评论标签""" # 在使用地方添加 {% comment_block request.path %} 使用。request.path为参数传递给comment_block() # return给block.html return { 'target': target, 'comment_form': CommentForm(), 'comment_list': Comment.get_by_target(target) }
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) comment_list = Comment.get_by_target(self.request.path) count = comment_list.count() context.update({ 'comment_form': CommentForm, 'comment_list': comment_list, }) print(context) return context