init.py:
# -*-coding:utf-8-*-
from flask import Flask
from sql_t import funk
from flask import jsonify
from flask import make_response
from flask import session
from flask import request
app = Flask(__name__,)
class Config(object):
DEBUG = True
app.config.from_object(Config)
app.config["SECRET_KEY"]='ajdooenxojajoa'
@app.route('/', methods=['POST', 'GET'])
def index():
data = funk()
resp = make_response(jsonify(data))
if request.method == 'GET':
#session 需要设置SECRET_KEY,否则报错
session["name"] = "python"
resp.set_cookie(u'Lw', u'Lw_')
return resp
elif request.method == 'POST':
return resp
if __name__ == '__main__':
app.run()
manager.py:
# -*-coding:utf-8-*-
from flask_script import Manager
from main import app
from flask import Flask
manager = Manager(app)
if __name__ == '__main__':
manager.run()
sql_t.py:
import sqlite3
def funk():
conn = sqlite3.connect('sample.db')
sur = conn.cursor()
sur.execute('select * from posts')
result = sur.fetchall()
return result
网友评论