Advertisement
Guest User

Sample

a guest
Jul 22nd, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. from bottle import route, run, template, static_file
  2. import mysql.connector
  3. from mysql.connector import errorcode
  4.  
  5.  
  6. def connectDB():
  7.     try:
  8.         cnn = mysql.connector.connect(
  9.             host="localhost",
  10.             user="XXXXXX",  # your username
  11.             password='XXXXX',
  12.             database="XXXXXX")  # name of the data base
  13.         print("It Works!!")
  14.     except mysql.connector.Error as e:
  15.         if e.errno == errorcode.ER_ACCESS_DENIED_ERROR:
  16.             print("Something is wrong with username or Password")
  17.         elif e.errno == errorcode.ER_BAD_DB_ERROR:
  18.             print("Database Does not exist")
  19.         else:
  20.             print(e)
  21.  
  22.     return cnn
  23.  
  24. @route('/')
  25. def home():
  26.     cnn = connectDB()
  27.     cursor = cnn.cursor()
  28.     cursor.execute("SELECT item_title,item_price FROM inventory")
  29.     results = cursor.fetchall()
  30.     cursor.close()
  31.     output = template('home', rows=results)
  32.     return output
  33.  
  34. @route('/static/:path#.+#', name='static')
  35. def static(path):
  36.     return static_file(path, root='static')
  37.  
  38. run(host='0.0.0.0', port=8080)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement