Guest User

Untitled

a guest
Oct 19th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. from flask import Flask, request
  2. from mysql.connector import connect
  3.  
  4. def connect_to_db(db_name):
  5. cnx = connect(user="root", password="", host="localhost", database=db_name)
  6. cnx.autocommit = True
  7. return cnx
  8.  
  9. app = Flask(__name__)
  10.  
  11. @app.route("/")
  12. def main_page():
  13. html = """
  14. <html>
  15. <head>
  16. <title>Deletion</title>
  17. </head>
  18. <body>
  19. {}
  20. </body>
  21. </html>
  22. """
  23. try:
  24. cnx = connect_to_db("exercises_db")
  25. cur = cnx.cursor()
  26. my_id = request.args.get("id")
  27. sql = "DELETE FROM product WHERE id={};".format(my_id)
  28. cur.execute(sql)
  29. html = html.format("Usunięto produkt")
  30.  
  31. cur.close()
  32. cnx.close()
  33. except Exception as e:
  34. print("An error occurred")
  35. print(e)
  36.  
  37. return html
  38.  
  39. app.run()
Add Comment
Please, Sign In to add comment