From 3b22586890425c8b8e555bce649649228b26c02b Mon Sep 17 00:00:00 2001 From: Mitsuo Tokumori Date: Sun, 29 Oct 2023 14:28:43 -0500 Subject: Add students blueprint using psycopg --- ustayml/views/blog.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ustayml/views/blog.py') diff --git a/ustayml/views/blog.py b/ustayml/views/blog.py index 57ba4ba..165d358 100644 --- a/ustayml/views/blog.py +++ b/ustayml/views/blog.py @@ -15,7 +15,7 @@ def index(): db = get_db() posts = db.execute( 'SELECT p.id, title, body, created, author_id, username' - ' FROM post p JOIN user u ON p.author_id = u.id' + ' FROM post p JOIN \"user\" u ON p.author_id = u.id' ' ORDER BY created DESC' ).fetchall() return render_template('blog/index.html', posts=posts) @@ -38,7 +38,7 @@ def create(): db = get_db() db.execute( 'INSERT INTO post (title, body, author_id)' - ' VALUES (?, ?, ?)', + ' VALUES (%s, %s, %s)', (title, body, g.user['id']) ) db.commit() @@ -65,8 +65,8 @@ def update(id): else: db = get_db() db.execute( - 'UPDATE post SET title = ?, body = ?' - ' WHERE id = ?', + 'UPDATE post SET title = %s, body = %s' + ' WHERE id = %s', (title, body, id) ) db.commit() @@ -80,7 +80,7 @@ def update(id): def delete(id): get_post(id) db = get_db() - db.execute('DELETE FROM post WHERE id = ?', (id,)) + db.execute('DELETE FROM post WHERE id = %s', (id,)) db.commit() return redirect(url_for('blog.index')) @@ -90,8 +90,8 @@ def delete(id): def get_post(id, check_author=True): post = get_db().execute( 'SELECT p.id, title, body, created, author_id, username' - ' FROM post p JOIN user u ON p.author_id = u.id' - ' WHERE p.id = ?', + ' FROM post p JOIN \"user\" u ON p.author_id = u.id' + ' WHERE p.id = %s', (id,) ).fetchone() -- cgit v1.2.3