def display_html(self): """ 直接渲染模板 """ from article.models import Post from comment.models import Comment result = '' if self.type == self.TYPE_NORMAL: # result = self.content # 添加每日一句 result = self.get_chicken_soup() elif self.type == self.TYPE_RECENT: context = {'posts': Post.get_latest_posts()} result = render_to_string('config/block/sidebar_posts.html', context) elif self.type == self.TYPE_HOT: context = {'posts': Post.get_hottest_posts()} result = render_to_string('config/block/sidebar_posts.html', context) elif self.type == self.TYPE_COMMENTS: context = {'comments': Comment.get_recently_comments()} result = render_to_string('config/block/sidebar_comments.html', context) return result