fix django views counter
问题 I am creating a blog using Django , and I want to count the views for each post. I call this function when a user reads the blog post: def post_detail(request, post_id): if 'viewed_post_%s' % post_id in request.session: pass else: print "adding" add_view = Post.objects.get(id=post_id) add_view.views += 1 add_view.save() request.session['viewed_post_%s' % post_id] = True return render(request, 'blog/detail.html', {'Post': Post.objects.get(id=post_id)}) The problem is that when logging out and