コード例 #1
0
ファイル: views.py プロジェクト: tkrevh/flask-starter-blog
def view_post(id):
    post = Post.query.get_or_404(id)
    form = CommentForm()
    
    if form.validate_on_submit():
        if not current_user.can_comment:
          abort(404)
        comment = Comment()
        form.populate_obj(comment)
        comment.author_id = current_user.id
        comment.post_id = post.id
        db.session.add(comment)
        db.session.commit()
        flash("New Comment successfully added")
        return redirect(url_for("view_post", id=post.id))
    return render_template("content/view_post.html", post=post, form=form)