You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
956 B

from flask import Flask, render_template, request, redirect
import mysql.connector
import os
mydb = mysql.connector.connect(
host=os.environ.get("HOST"),
user=os.environ.get("USER"),
password=os.environ.get("PASSWORD"),
database="new_trello"
)
mydb.autocommit = True
cursor = mydb.cursor()
app = Flask(__name__)
@app.get("/")
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']])
return redirect('/')
@app.post("/<id>")
def delete(id):
# print(request.args.get('_method'))
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
return redirect('/')
@app.get("/<id>")
def show(id):
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
return render_template('show.html', cursor=cursor)