Пример #1
0
def home(request):
    context = {}
    hot_blogs_for_7_days = cache.get('hot_blogs_for_7_days')
    if hot_blogs_for_7_days is None:
        hot_blogs_for_7_days = get_7_days_hot_blogs()
        cache.set('hot_blogs_for_7_days', hot_blogs_for_7_days, 3600)

    blog_content_type = ContentType.objects.get_for_model(Blog)  # 传入Blog
    dates, read_nums = get_seven_days_read_data(blog_content_type)
    context['today_hot_data'] = get_today_hot_data(blog_content_type)
    context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type)
    context['hot_blogs_for_7_days'] = hot_blogs_for_7_days
    context['dates'] = dates
    context['read_nums'] = read_nums
    return render(request, 'home.html', context)
Пример #2
0
def home(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates,read_nums = get_seven_days_read_data(blog_content_type)

    #获取缓存
    week_hot_data = cache.get('week_hot_data')
    if week_hot_data is None:
        week_hot_data = get_week_hot_data()
        cache.set('week_hot_data', week_hot_data, 3600)

    context = {}
    context['read_nums'] = read_nums
    context['dates'] = dates
    context['today_hot_data'] = get_today_hot_data(blog_content_type)
    context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type)
    context['week_hot_data'] = get_week_hot_data()
    return render(request, 'home.html', context)
    
Пример #3
0
def home(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates, read_nums = get_seven_days_read_data(content_type=blog_content_type)
    today_hot_data = get_today_hot_data(blog_content_type)
    yesterday_hot_data = get_yesterday_hot_data(blog_content_type)
    # seven_hot_data=get_7_days_hot_blogs()
    # 获取7天热门博客的缓存数据
    hot_blog_for_seven_days = cache.get('hot_blog_for_seven_days')
    if hot_blog_for_seven_days is None:
        hot_blog_for_seven_days = get_7_days_hot_blogs()
        cache.set('hot_blog_for_seven_days', hot_blog_for_seven_days, 3600)
    context = {
        'read_nums': read_nums,
        'dates': dates,
        'today_hot_data': today_hot_data,
        'yesterday_hot_data': yesterday_hot_data,
        'seven_hot_data': hot_blog_for_seven_days
    }
    return render(request, 'blogger/home.html', context)
Пример #4
0
    def get(self, request):
        blog_content_type = ContentType.objects.get_for_model(Blog)
        dates, read_nums = get_seven_days_read_data(blog_content_type)
        today_hot_data = get_today_hot_data(blog_content_type)
        yesterday_hot_data = get_yesterday_hot_data(blog_content_type)

        # 获取一周热门博客的缓存数据
        week_hot_blogs = cache.get('week_hot_blogs')
        if week_hot_blogs is None:
            week_hot_blogs = get_week_hot_blogs()
            cache.set('week_hot_blogs', week_hot_blogs, 3600)

        context = {}
        context['dates'] = dates
        context['read_nums'] = read_nums
        context['today_hot_data'] = today_hot_data
        context['yesterday_hot_data'] = yesterday_hot_data
        context['week_hot_blogs'] = week_hot_blogs
        return render(request, 'home.html', context)
Пример #5
0
def home(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates, read_nums = get_seven_days_read_data(blog_content_type)

    #獲取熱門文章緩存數據
    hot_blogs_for_7_days = cache.get('hot_blogs_for_7_days')
    if hot_blogs_for_7_days is None:
        hot_blogs_for_7_days = get_7_days_hot_blogs()
        cache.set('hot_blogs_for_7_days', hot_blogs_for_7_days, 60 * 60 * 24)
        print('calc')
    else:
        print('use cache')

    context = {}
    context['dates'] = dates
    context['read_nums'] = read_nums
    context['today_hot_data'] = get_today_hot_data(blog_content_type)
    context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type)
    context['hot_blogs_for_7_days'] = hot_blogs_for_7_days
    return render(request, 'home.html', context)