def blog(id): if id is None: abort(404) blog = Blog.query.filter_by(id=int(id)).first() if blog is None: abort(404) form = CommentForm() if current_user.has_permission(Permission.COMMENT): if form.validate_on_submit(): comment = Comment() comment.blog_id = blog.id comment.author_id = current_user.id comment.body = form.comment.data comment.disabled = False db.session.add(comment) db.session.commit() return redirect(url_for('main.blog', id=blog.id)) # comments = Comment.query.filter_by(blog_id = blog.id).all() page = request.args.get('page', type=int, default=1) pagination = blog.comments.order_by(Comment.time.desc()).paginate( page, 3, False) comments = pagination.items return render_template('main/blog.html', blog=blog, form=form, comments=comments, pagination=pagination)