-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathposts.py
More file actions
38 lines (30 loc) · 901 Bytes
/
posts.py
File metadata and controls
38 lines (30 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import (
Blueprint,
redirect,
render_template,
request,
url_for,
)
from board.database import get_db
bp = Blueprint("posts", __name__)
@bp.route("/create", methods=("GET", "POST"))
def create():
if request.method == "POST":
author = request.form["author"] or "Anonymous"
message = request.form["message"]
if message:
db = get_db()
db.execute(
"INSERT INTO post (author, message) VALUES (?, ?)",
(author, message),
)
db.commit()
return redirect(url_for("posts.posts"))
return render_template("posts/create.html")
@bp.route("/posts")
def posts():
db = get_db()
posts = db.execute(
"SELECT author, message, created FROM post ORDER BY created DESC"
).fetchall()
return render_template("posts/posts.html", posts=posts)