diff --git a/server.py b/server.py index f6f53c5..3e0ca9c 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,4 @@ from flask import Flask, render_template, request, redirect -# import mariadb import mysql.connector import os @@ -14,17 +13,22 @@ cursor = mydb.cursor() app = Flask(__name__) @app.get("/") -def show(): +def show_all(): cursor.execute('SELECT * FROM items') return render_template('show.html', cursor=cursor) @app.post("/") def create(): - cursor.execute('INSERT INTO items (title, description) VALUES(%s,%s)', (request.form['title'],request.form['description'])) + cursor.execute('INSERT INTO items (title, description) VALUES(%s,%s)', [request.form['title'],request.form['description']]) return redirect('/') @app.post("/") def delete(id): # print(request.args.get('_method')) - cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [int(id)]) + cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id]) return redirect('/') + +@app.get("/") +def show(id): + cursor.execute('SELECT * FROM items WHERE id=%s', [id]) + return render_template('show.html', cursor=cursor) diff --git a/templates/show.html b/templates/show.html index 0100341..f4e42ed 100644 --- a/templates/show.html +++ b/templates/show.html @@ -9,7 +9,7 @@