def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_num(blog_content_type) today_hot_data = get_today_hot_data(blog_content_type) yesterday_hot_data = get_yesterday_hot_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, 3600) context = {} context['read_nums'] = read_nums context['dates'] = dates context['today_hot_data'] = today_hot_data context['yesterday_hot_data'] = yesterday_hot_data context['get_7_days_hot_date'] = get_7_days_hot_date(blog_content_type) return render(request, 'home.html', context)
def home(request): # 获取7天热门博客的缓存数据 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_data_hot_blogs() cache.set('hot_blogs_for_7_days', hot_blogs_for_7_days, 60) print('计算缓存') else: print('use 缓存') 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) context = {'read_nums': read_nums, 'dates': dates, 'today_hot_data': today_hot_data, 'yesterday_hot_data': yesterday_hot_data, 'hot_blogs_for_7_days': hot_blogs_for_7_days} return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_date(blog_content_type) # 获取7天热门博客的缓存数据 hot_blogs_for_7_days = cache.get('hot_blogs_for_7_days') if not hot_blogs_for_7_days: hot_blogs_for_7_days = get_7_days_hot_blogs() cache.set('hot_blogs_for_7_days', hot_blogs_for_7_days, 3600) 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'] = get_7_days_hot_blogs() return render(request, "home.html", context)
def home(request): blog_content_type=ContentType.objects.get_for_model(Blog) read_seven_num,dates=get_seven_days_read_date(blog_content_type) hot_data_for_7days=cache.get('hot_data_for_7days') if hot_data_for_7days is None: hot_data_for_7days = get_7days_hot_data() cache.set('hot_data_for_7days',hot_data_for_7days,3600) hot_data_for_yesterday=cache.get('hot_data_for_yesterday') if hot_data_for_yesterday is None: hot_data_for_yesterday=get_yesterday_hot_data(blog_content_type) cache.set('hot_data_for_yesterday', hot_data_for_yesterday, 3600) context={} context['read_seven_num']=read_seven_num context['dates']=dates context['read_today_hot'] = get_today_hot_data(blog_content_type) context['read_yesterday_hot'] = hot_data_for_yesterday context['hot_data_for_7days'] = hot_data_for_7days return render(request,'home.html',context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) read_nums, dates = 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) seven_days_hot_data = cache.get('seven_days_hot_data') if seven_days_hot_data is None: seven_days_hot_data = get_7_days_hot_blogs() cache.set('seven_days_hot_data', seven_days_hot_data, 3600) context = {} context['read_nums'] = read_nums context['today_hot_data'] = today_hot_data context['yesterday_hot_data'] = yesterday_hot_data context['seven_days_hot_data'] = get_7_days_hot_blogs() context['dates'] = dates return render(request, "home.html", context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) # 获取7天热门博客的缓存数据 week_hot_dat = cache.get('week_hot_dat') if week_hot_dat is None: week_hot_dat = get_week_hot_blogs() cache.set('get_week_hot_blogs', week_hot_dat, 3600) #一个小时=3600 context = {} context['dates'] = dates context['read_nums'] = read_nums context['today_hot_dat'] = get_today_hot_data(blog_content_type) context['yesterday_hot_dat'] = get_yesterday_hot_data(blog_content_type) context['week_hot_dat'] = week_hot_dat return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = utils.get_seven_days_read_data(blog_content_type) # 获取七天热门博客的缓存数据 hot_data_7days = cache.get('get_7days_hot_data') if hot_data_7days is None: hot_data_7days = utils.get_7days_hot_data(blog_content_type) cache.set('get_7days_hot_data', hot_data_7days, 3600) context = {} context['today_hot_data'] = utils.get_today_hot_data(blog_content_type) context['yesterday_hot_data'] = utils.get_yesterday_hot_data( blog_content_type) context['hot_data_7days'] = hot_data_7days context['dates'] = dates context['read_nums'] = read_nums return render(request, 'home.html', context)
def home(request): # 获取最近7天的阅读量 blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) # 获取7天热门博客的缓存数据 hot_blogs_for_7_days = cache.get('hot_blogs_for_7_days') if hot_blogs_for_7_days is None: cache.set('hot_blogs_for_7_days', hot_blogs_for_7_days, 3600) print('cal') else: print('use cache') context = {} context['read_nums'] = read_nums context['dates'] = dates context['today_hot_data'] = get_today_hot_data(blog_content_type) context['hot_blogs_for_7_days'] = get_7_days_hot_blog return render(request, 'home.html', context)
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, 3600) context = { 'read_nums': read_nums, 'dates': dates, 'today_hot_data': get_today_hot_data(blog_content_type), 'get_yesterday_hot_data': get_yesterday_hot_data(blog_content_type), 'hot_blogs_for_7_days': hot_blogs_for_7_days } return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_week_read_data(blog_content_type) # 设置缓存 week_hot_data = get_week_hot_data() hot_blogs_for_week = cache.get('hot_blogs_for_week') if hot_blogs_for_week is None: hot_blogs_for_week = week_hot_data cache.set('hot_blogs_for_week', hot_blogs_for_week, 3600) 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['week_hot_data'] = week_hot_data return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_week_read_data(blog_content_type) # 获取近一周热门博客的缓存数据 week_hot_blogs = cache.get('week_hot_blogs') if week_hot_blogs is None: week_hot_blogs = get_week_hot_data() cache.set('week_hot_blogs', week_hot_blogs, 3600) context = { 'dates': dates, 'read_nums': read_nums, 'today_hot_data': get_today_hot_data(blog_content_type), 'yesterday_hot_data': get_yesterday_hot_data(blog_content_type), 'week_hot_blogs': week_hot_blogs, } return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) # 获取7天热门博客缓存数据 hot_blogs_for_days = cache.get('hot_blogs_for_days') if hot_blogs_for_days is None: hot_blogs_for_days = get_days_hot_blogs() cache.set('hot_blogs_for_days', hot_blogs_for_days, 3600) print('calc') else: print("use cache") context = {} pass 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['hot_blogs_for_days'] = get_days_hot_blogs() return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) #获取7天热门博客的缓存数据 hot_data_for_7_days = cache.get('hot_data_for_7_days') if hot_data_for_7_days is None: hot_data_for_7_days = get_7_days_hot_blogs() cache.set('hot_data_for_7_days', hot_data_for_7_days, 3600) #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['hot_data_for_7_days'] = hot_data_for_7_days return render(request, 'home.html', context) from .form import LoginForm, RegForm
def index(request): blog_content_type = ContentType.objects.get_for_model(Article) dates, read_nums = get_preSevenDays_readnum(blog_content_type) today_hot_data = get_today_hot_data(blog_content_type) # hot_data_for_7_days = get_7_days_hot_data(blog_content_type) # hot_data_for_7_days = get_7_days_hot_blogs(hot_data_for_7_days) #获取七天热门博客的缓存数据 hot_data_for_7_days = cache.get('hot_data_for_7_days') if hot_data_for_7_days is None: hot_data_for_7_days = get_7_days_hot_blogs_teacher() cache.set('hot_data_for_7_days',hot_data_for_7_days,3600) content = {} content['read_nums'] = read_nums content['dates'] = dates content['today_hot_data'] = today_hot_data content['hot_data_for_7_days'] = hot_data_for_7_days return render(request, "index.html",content)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) read_nums, dates = get_seven_days_date(blog_content_type) today_hot_data = get_today_hot_data(blog_content_type) yesterday_hot_data = get_yesterday_hot_data(blog_content_type) # gain the hot blogs' data in seven days for_7_days_hot_data = cache.get('for_7_days_hot_data') if for_7_days_hot_data is None: for_7_days_hot_data = get_seven_days_hot_blogs() cache.set('for_7_days_hot_data', for_7_days_hot_data, 3600) context = {} context['read_nums'] = read_nums context['dates'] = dates context['today_hot_data'] = today_hot_data context['yesterday_hot_data'] = yesterday_hot_data context['for_7_days_hot_data'] = for_7_days_hot_data return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(blogv1) dates, read_nums = get_seven_days_read_data(blog_content_type) # 获取7天热门博客的缓存数据 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, 600) context = {} context['blognum'] = blogv1.objects.filter(is_deleted=False).count() 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['blog_types'] = BlogType.objects.annotate( blog_count=Count('blogv1')) context['hot_blogs_for_7_days'] = hot_blogs_for_7_days return render(request, 'blog/home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) blogs_all_nums = Blog.objects.filter(is_deleted=False).count() blog_types = BlogType.objects.all() blog_types_list = [] for blog_type in blog_types: blog_type.blog_count = Blog.objects.filter(blog_type=blog_type).count() blog_types_list.append(blog_type) # 获取7天热门博客的缓存数据 hot_blogs_for_7_days = cache.get('hot_blogs_for_7_days') # 获取30天热门博客的缓存数据 hot_blogs_for_30_days = cache.get('hot_blogs_for_30_days') # 获取总热门博客的缓存数据 hot_blogs_for_all_days = cache.get('hot_blogs_for_all_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) # 缓存1小时 if hot_blogs_for_30_days is None: hot_blogs_for_30_days = get_30_days_hot_blogs() cache.set('hot_blogs_for_30_days', hot_blogs_for_30_days, 3600) # 缓存1小时 if hot_blogs_for_all_days is None: hot_blogs_for_all_days = get_all_days_hot_blogs() cache.set('hot_blogs_for_all_days', hot_blogs_for_all_days, 3600) # 缓存1小时 context = dict() 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 context['hot_blogs_for_30_days'] = hot_blogs_for_30_days context['hot_blogs_for_all_days'] = hot_blogs_for_all_days context['blog_types'] = blog_types_list context['blogs_all_nums'] = blogs_all_nums return render(request, 'home.html', context)
def home(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) 改成get_today_hot_data(blog_content_type)后删除 # 获取7天热门博客的缓存数据 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) # 设置缓存(缓存对象,缓存内容,有效期) 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'] = get_7_days_hot_blogs() return render(request, 'home.html', context)
def index(request): # 首页 blog_content_type = ContentType.objects.get_for_model(Blog) read_nums, read_date = get_even_week_read_num(blog_content_type) #获取缓存数据 seven_days_hot_data = cache.get('seven_days_hot_data') if seven_days_hot_data is None: #缓存不存在则计算并存入缓存 seven_days_hot_data = get_7_days_hot_data() cache.set('seven_days_hot_data', seven_days_hot_data, 3600) # 存入缓存,并设置缓存保存时间为一个小时 context = {} context['read_nums'] = read_nums context['read_date'] = list(read_date) context['today_hot_data'] = get_today_hot_data(blog_content_type) context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type) context['seven_days_hot_data'] = seven_days_hot_data # 使用缓存 return render(request, "index.html", context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) #获取7天热门博客的缓存数据 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) # print('计算缓存') # else: # print('使用缓存') 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)
def home(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) #获取七天热门博客的缓存数据 hot_data_for_7_blogs = cache.get('hot_data_for_7_blogs') if hot_data_for_7_blogs is None: hot_data_for_7_blogs = get_7_days_hot_blogs() cache.set('hot_data_for_7_blogs',hot_data_for_7_blogs,60*60) #保存一小时 context ={} context['read_nums'] = read_nums context['dates'] = dates context['today_hot_data']= today_hot_data context['yesterday_hot_data'] = yesterday_hot_data context['hot_data_for_7_blogs'] = hot_data_for_7_blogs return render(request,'home.html',context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates_list, read_nums_list = 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) # 获取七天热门博客的缓存数据 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) data = { 'read_nums_list': read_nums_list, 'dates_list': dates_list, 'today_hot_data': today_hot_data, 'yesterday_hot_data': yesterday_hot_data, 'hot_blogs_for_7_days': hot_blogs_for_7_days, } return render(request, 'home.html', context=data)
def home(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) sevenday_hot_data = cache.get("sevenday_hot_data") if sevenday_hot_data is None: sevenday_hot_data = get_7_hot_data() cache.set("sevenday_hot_data", sevenday_hot_data, 3600) context = {} context["read_nums"] = read_nums context["dates"] = dates context["today_hot_data"] = today_hot_data context["yesterday_hot_data"] = yesterday_hot_data context["sevenday_hot_data"] = sevenday_hot_data #return render_to_response("home.html", context) return render(request, "home.html", context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) blogs_all_list = Blog.objects.all() dates, read_nums = get_seven_days_read_data(blog_content_type) #获取7天热门博客的缓存数据 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) context = get_blog_list_common_data(request, blogs_all_list) context['dates'] = dates context['user'] = request.user 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'] = get_7_days_hot_blogs() return render(request, "home.html", context)
def base(request): topic_content_type = ContentType.objects.get_for_model(Topic) read_nums, dates = get_seven_days_read_data(topic_content_type) # 获取7天热门博客的缓存数据 hot_data_for_7_days = cache.get('hot_data_for_7_days') if hot_data_for_7_days is None: hot_data_for_7_days = get_7_days_hot_data() cache.set('hot_data_for_7_days', hot_data_for_7_days, 3600) print('calc') else: print('use cache') context = {} context['dates'] = dates context['read_nums'] = read_nums context['yesterday_hot_data'] = get_yesterday_hot_data(topic_content_type) context['today_hot_data'] = get_today_hot_data(topic_content_type) context['hot_data_for_7_days'] = get_7_days_hot_data() return render(request, 'index.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(blog_content_type) # 获取 7 天的缓存数据 seven_days_hot_data = cache.get('seven_days_hot_data') if seven_days_hot_data is None: seven_days_hot_data = get_seven_days_hot_blogs() cache.set('seven_days_hot_data', seven_days_hot_data, 3600) print('缓存') else: print('使用缓存') 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['seven_days_hot_data'] = seven_days_hot_data return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data( blog_content_type) # 获取日期及对应的博客文章点击量 # 获取7天热门博客的缓存数据 hot_blogs_for_7_days = cache.get('get_seven_days_hot_blogs') if hot_blogs_for_7_days is None: hot_blogs_for_7_days = get_seven_days_hot_blogs() cache.set('get_seven_days_hot_blogs', hot_blogs_for_7_days, 60 * 60) print('create cache') 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['get_seven_days_hot_blogs'] = get_seven_days_hot_blogs() return render_to_response('home.html', context)
def home(request): polls_content_type = ContentType.objects.get_for_model(Polls) dates, read_nums = get_seven_days_read_data(polls_content_type) #获取7天热门博客的缓存数据 seven_day_hot_data = cache.get('seven_day_hot_data') if seven_day_hot_data is None: seven_day_hot_data = get_seven_day_hot_data() cache.set('seven_day_hot_data', seven_day_hot_data, 0) print('calc') else: print('use cache') context = {} context['dates'] = dates context['read_nums'] = read_nums context['today_hot_data'] = get_today_hot_data(polls_content_type) context['yesterday_hot_data'] = get_yesterday_hot_data(polls_content_type) context['seven_day_hot_data'] = seven_day_hot_data return render(request, 'home.html', context)
def home(request): blog_content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_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) last_week_hot_data = cache.get('last_week_hot_data') if last_week_hot_data is None: last_week_hot_data = get_last_week_hot_data() cache.set('last_week_hot_data', last_week_hot_data, 3600) 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['last_week_hot_data'] = last_week_hot_data return render(request, 'home.html', context)
def home(request): content_type = ContentType.objects.get_for_model(Blog) dates, read_nums = get_seven_days_read_data(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, 3600) blog_types_list = BlogType.objects.annotate(blog_count=Count('blog')) context = {} context['blog_types'] = blog_types_list context['blog_of_all_nums'] = Blog.objects.all().count() context['read_nums'] = read_nums context['dates'] = dates context['today_hot_data'] = get_today_hot_data(content_type) context['yesterday_hot_data'] = get_yesterday_hot_data(content_type) context['hot_blogs_for_7_days'] = hot_blogs_for_7_days return render(request, 'home.html', context)