Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bottle import route, run, template, static_file
- import mysql.connector
- from mysql.connector import errorcode
- def connectDB():
- try:
- cnn = mysql.connector.connect(
- host="localhost",
- user="XXXXXX", # your username
- password='XXXXX',
- database="XXXXXX") # name of the data base
- print("It Works!!")
- except mysql.connector.Error as e:
- if e.errno == errorcode.ER_ACCESS_DENIED_ERROR:
- print("Something is wrong with username or Password")
- elif e.errno == errorcode.ER_BAD_DB_ERROR:
- print("Database Does not exist")
- else:
- print(e)
- return cnn
- @route('/')
- def home():
- cnn = connectDB()
- cursor = cnn.cursor()
- cursor.execute("SELECT item_title,item_price FROM inventory")
- results = cursor.fetchall()
- cursor.close()
- output = template('home', rows=results)
- return output
- @route('/static/:path#.+#', name='static')
- def static(path):
- return static_file(path, root='static')
- run(host='0.0.0.0', port=8080)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement