Create a new post for the current user.
()
| 60 | @bp.route("/create", methods=("GET", "POST")) |
| 61 | @login_required |
| 62 | def 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")) |
nothing calls this directly
no test coverage detected