def post(post_id): post = Post.query.get_or_404(post_id) form = CommentForm() if form.validate_on_submit(): comment_post = Comment(content=form.content.data, entry=post, author=current_user) db.session.add(comment_post) db.session.commit() flash('Your comment has been created!', 'success') return redirect(url_for('post',post_id=post.id)) comment = Comment.query.filter_by(post_id=post_id).order_by(Comment.date_posted.desc()).all() return render_template('post.html', post=post, form=form, comment=comment)
def create_comment(post_id): post = Post.query.get(post_id) form = CommentForm() if form.validate_on_submit(): comment = Comment(content=form.content.data, author=current_user, ref_post=post) db.session.add(comment) db.session.commit() return redirect(url_for('post', post_id=post.id)) return render_template('create_comment.html', title=post.title, post=post, legend='New Comment', form=form)