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

Function create

examples/tutorial/flaskr/blog.py:62–83  ·  view source on GitHub ↗

Create a new post for the current user.

()

Source from the content-addressed store, hash-verified

60@bp.route("/create", methods=("GET", "POST"))
61@login_required
62def create():
63 """Create a new post for the current user."""
64 if request.method == "POST":
65 title = request.form["title"]
66 body = request.form["body"]
67 error = None
68
69 if not title:
70 error = "Title is required."
71
72 if error is not None:
73 flash(error)
74 else:
75 db = get_db()
76 db.execute(
77 "INSERT INTO post (title, body, author_id) VALUES (?, ?, ?)",
78 (title, body, g.user["id"]),
79 )
80 db.commit()
81 return redirect(url_for("blog.index"))
82
83 return render_template("blog/create.html")
84
85
86@bp.route("/<int:id>/update", methods=("GET", "POST"))

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected