Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bottle import route, run, template, static_file
- from bottle.ext import sqlite
- import time
- app = bottle.Bottle()
- sqlitePlugin = sqlite.Plugin(dbfile = 'chat.db')
- app.install(sqlitePlugin)
- @route('/')
- def index():
- return template('index.html')
- @app.get('/gallery')
- def main(db):
- return main_template(db)
- @app.post('gallery')
- def send_message(db):
- author = bottle.request.forms.getunicode("author")
- msg = bottle.request.forms.getunicode("msg")
- db.execute("insert into Messages (author, msg, time) values ('{}','{}','{}')".format(author,msg,int(time.time())))
- db.commit()
- return main_template(db)
- def main_template(db):
- messages = db.execute('select author, msg from Messages order by time desc').fetchall()
- return bottle.template('gallery', messages = messages)
- @route('/contacts')
- def contacts():
- return template('contacts.html'),main_template()
- @route('/static/<path:path>')
- def callback(path):
- return static_file(path,'static')
- app.run(host = 'localhost', port = 8080)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement