def get_context_data(self,*args,**kwargs): context = super(BaseMixin,self).get_context_data(**kwargs) try: context['categories'] = Category.available_list() context['widgets'] = Widget.available_list() context['recently_posts'] = Post.get_recently_posts(RECENTLY_NUM) context['hot_posts'] = Post.get_hots_posts(HOT_NUM) context['pages'] = Page.objects.filter(status=0) if cache.get('online.ips')!= None: context['online_num'] = len(cache.get('online_ips')) except Exception as e: logger.exception(u'加载基本信息出错[%s]',e) return context
def get_context_data(self, *args, **kwargs): if 'object' in kwargs or 'query' in kwargs: context = super(BaseMixin, self).get_context_data(**kwargs) else: context = {} try: context['categories'] = Category.available_list() context['widgets'] = Widget.available_list() context['recently_posts'] = Post.get_recently_posts(RECENTLY_NUM) context['hot_posts'] = Post.get_hots_posts(HOT_NUM) context['tag_lists'] = Post.gather_tags() context['like_most_posts'] = Post.get_most_like_posts(LIKE_MOST_NUM) context['pages'] = Page.objects.filter(status=0) except Exception as e: logger.exception(u'加载基本信息出错[%s]!', e) return context
def get_context_data(self, *args, **kwargs): if 'object' in kwargs or 'query' in kwargs: context = super(BaseMixin, self).get_context_data(**kwargs) else: context = {} try: context['categories'] = Category.available_list() context['widgets'] = Widget.available_list() context['recently_posts'] = Post.get_recently_posts(RECENTLY_NUM) context['hot_posts'] = Post.get_hots_posts(HOT_NUM) context['tag_lists'] = Post.gather_tags() context['like_most_posts'] = Post.get_most_like_posts( LIKE_MOST_NUM) context['pages'] = Page.objects.filter(status=0) except Exception as e: logger.exception(u'加载基本信息出错[%s]!', e) return context
def add_context_data(self, **kwargs): # 这里重载了ListView的get_context_data方法 context = super(BaseMixin, self).get_context_data(**kwargs) try: context['categories'] = Category.available_list() context['widgets'] = Widget.available_list() context['recently_posts'] = Post.get_recently_posts( settings.RECENTLY_NUM) context['hot_posts'] = Post.get_hots_posts(settings.HOT_NUM) context['pages'] = Page.objects.filter(status=0) if not context.has_key('title'): context['title'] = '' context['title'] += 'Younfor' context['desc'] = 'python,c,c++,java,linux,生活感悟,工作笔记,心情驿站' context['keywords'] = 'python,c,c++,java,linux,生活感悟,工作笔记,心情驿站' context['author'] = 'younfor' context['sitename'] = 'Younfor\'s BLOG' context['blogdesc'] = '悄悄是别离的笙箫,所谓爱情,所谓人生,所谓。' except Exception as e: print e return context