MCPcopy
hub / github.com/pallets/flask / update

Function update

examples/tutorial/flaskr/blog.py:88–110  ·  view source on GitHub ↗

Update a post if the current user is the author.

(id)

Source from the content-addressed store, hash-verified

86@bp.route("/<int:id>/update", methods=("GET", "POST"))
87@login_required
88def update(id):
89 """Update a post if the current user is the author."""
90 post = get_post(id)
91
92 if request.method == "POST":
93 title = request.form["title"]
94 body = request.form["body"]
95 error = None
96
97 if not title:
98 error = "Title is required."
99
100 if error is not None:
101 flash(error)
102 else:
103 db = get_db()
104 db.execute(
105 "UPDATE post SET title = ?, body = ? WHERE id = ?", (title, body, id)
106 )
107 db.commit()
108 return redirect(url_for("blog.index"))
109
110 return render_template("blog/update.html", post=post)
111
112
113@bp.route("/<int:id>/delete", methods=("POST",))

Callers

nothing calls this directly

Calls 6

flashFunction · 0.90
redirectFunction · 0.90
url_forFunction · 0.90
render_templateFunction · 0.90
get_postFunction · 0.85
get_dbFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…