Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from bottle import route, run, template, static_file
  2. from bottle.ext import sqlite
  3. import time
  4.  
  5. app = bottle.Bottle()
  6. sqlitePlugin = sqlite.Plugin(dbfile = 'chat.db')
  7. app.install(sqlitePlugin)
  8.  
  9. @route('/')
  10. def index():
  11.     return template('index.html')
  12.  
  13. @app.get('/gallery')
  14. def main(db):
  15.     return main_template(db)
  16.  
  17. @app.post('gallery')
  18. def send_message(db):
  19.     author = bottle.request.forms.getunicode("author")
  20.     msg = bottle.request.forms.getunicode("msg")
  21.     db.execute("insert into Messages (author, msg, time) values ('{}','{}','{}')".format(author,msg,int(time.time())))
  22.     db.commit()
  23.     return main_template(db)
  24.  
  25. def main_template(db):
  26.     messages = db.execute('select author, msg from Messages order by time desc').fetchall()
  27.     return bottle.template('gallery', messages = messages)
  28.  
  29. @route('/contacts')
  30. def contacts():
  31.     return template('contacts.html'),main_template()
  32.  
  33. @route('/static/<path:path>')
  34. def callback(path):
  35.     return static_file(path,'static')
  36.  
  37. app.run(host = 'localhost', port = 8080)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement