def post_new(): form = PostForm() if request.method == "POST" and form.validate(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash("Your post has been created!", "success") return redirect(url_for('post', id=post.id)) return render_template("post_new.html", title="Create New Post", form=form)
def edit_post(id: int): post = Post.query.get_or_404(id) if post.author != current_user: abort(403) form = PostForm() if request.method == "POST" and form.validate(): post.title = form.title.data post.content = form.content.data db.session.commit() flash("Your post has been updated!", "info") return redirect(url_for('post', id=post.id)) else: form.title.data = post.title form.content.data = post.content return render_template("edit_post.html", title="Update Post", form=form)