@app.route('/writedb',methods=['POST']) def writedb(): t = time.time() name = request.form['name'] content = request.form['content'] lyb = sqlite3.connect('lyb.db') homu = lyb.cursor() homu.execute('create table if not exists user (name,content,time)') homu.execute('insert into user (name,content,time) values (\'%s\',\'%s\', \'%s\' )' % (name ,content ,t)) for i in homu.execute('select * from user'): print i homu.close() lyb.commit() lyb.close() return 'Success'
@app.route('/readdb',methods=['POST']) def readdb(): lyb = sqlite3.connect('lyb.db') homu = lyb.cursor() r = [] for i in homu.execute('select * from user'): r.append(json.dumps({'name':i[0],'content':i[1],'time':i[2]})) for i in r: print i return jsonify(text = r) homu.close() lyb.commit() lyb.close()