|
|
|
@ -1,5 +1,4 @@
|
|
|
|
from flask import Flask, render_template, request, redirect
|
|
|
|
from flask import Flask, render_template, request, redirect
|
|
|
|
# import mariadb
|
|
|
|
|
|
|
|
import mysql.connector
|
|
|
|
import mysql.connector
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
@ -14,17 +13,22 @@ cursor = mydb.cursor()
|
|
|
|
app = Flask(__name__)
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
|
|
@app.get("/")
|
|
|
|
def show():
|
|
|
|
def show_all():
|
|
|
|
cursor.execute('SELECT * FROM items')
|
|
|
|
cursor.execute('SELECT * FROM items')
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/")
|
|
|
|
@app.post("/")
|
|
|
|
def create():
|
|
|
|
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('/')
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/<id>")
|
|
|
|
@app.post("/<id>")
|
|
|
|
def delete(id):
|
|
|
|
def delete(id):
|
|
|
|
# print(request.args.get('_method'))
|
|
|
|
# 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('/')
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/<id>")
|
|
|
|
|
|
|
|
def show(id):
|
|
|
|
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
|