@bp.route("<STR_LIT>", methods=("<STR_LIT:GET>", "<STR_LIT:POST>"))<EOL>@login_required<EOL>def update(id):
post = get_post(id)<EOL>if request.method == "<STR_LIT:POST>":<EOL><INDENT>title = request.form["<STR_LIT:title>"]<EOL>body = request.form["<STR_LIT:body>"]<EOL>error = None<EOL>if not title:<EOL><INDENT>error = "<STR_LIT>"<EOL><DEDENT>if error is not None:<EOL><INDENT>flash(error)<EOL><DEDENT>else:<EOL><INDENT>post.title = title<EOL>post.body = body<EOL>db.session.commit()<EOL>return redirect(url_for("<STR_LIT>"))<EOL><DEDENT><DEDENT>return render_template("<STR_LIT>", post=post)<EOL>
Update a post if the current user is the author.