def content_html(self): """直接渲染模板""" from main.models import Post # 避免循环引用 from comment.models import Comment result='' show_items_num=5 if self.display_type==self.DISPLAY_HTML: result=self.content elif self.display_type==self.DISPLAY_LATEST: context={ 'posts':Post.latest_posts()[:show_items_num] } tes=render_to_string('config/blocks/sidebar_posts.html',context=context) result=render_to_string('config/blocks/sidebar_posts.html',context=context) elif self.display_type==self.DISPLAY_HOT: context={ 'posts': Post.hot_posts()[:show_items_num], } result=render_to_string('config/blocks/sidebar_posts.html',context=context) elif self.display_type==self.DISPLAY_COMMENT: context={ 'comments': Comment.objects.filter(status=Comment.STATUS_NORMAL)[:show_items_num] } result=render_to_string('config/blocks/sidebar_comments.html',context=context) return result
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