def post(id): post = Post.query.get_or_404(id) form = forms.CommentForm() if request.method=='POST': comment = Comment() comment.content = form.content.html comment.user_id = current_user.id comment.post_id = id comment.time_stamp = datetime.now() db.session.add(comment) db.session.commit() return redirect(url_for('.post',id=id,page=-1)) page = request.args.get('page',1,type=int) if page==-1: page = (post.comments.count() - 1) / COMMENTS_PER_PAGE + 1 comments = post.comments.order_by(Comment.time_stamp.asc()).paginate(page,COMMENTS_PER_PAGE,False) Post.query.filter(Post.id==id).update({Post.view_times:Post.view_times+1}) return render_template('post.html',post=post,comments=comments,form=form)