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

Function update

examples/tutorial/flaskr/blog.py:88–110  ·  examples/tutorial/flaskr/blog.py::update

Update a post if the current user is the author.

(id)

Source from the content-addressed store, hash-verified

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