def content_html(self): """直接渲染模板""" from main.models import Post from comment.models import Comment from django.template.loader import render_to_string result = '' if self.display_type == self.DISPLAY_HTML: result = self.content elif self.display_type == self.DISPLAY_LATEST: context = {'posts': Post.latest_posts()} result = render_to_string('config/blocks/siderbar_posts.html', context) elif self.display_type == self.DISPLAY_HOT: context = {'posts': Post.hot_post()} result = render_to_string('config/blocks/siderbar_posts.html', context) elif self.display_type == self.DISPLAY_COMMENT: context = { 'comments': Comment.objects.filter( status=Comment.STATUS_NORMAL) #此处为什么是用Comment类来调用?? } result = render_to_string('config/blocks/siderbar_comments.html', context) return result