def __init__(self): super(Application, self).__init__(url_patterns, **settings) #数据库 engine = create_engine(DB_CONNECT_STRING,encoding=DB_ENCODING, echo=DB_ECHO) self.db = scoped_session(sessionmaker(bind=engine)) init_db(engine)#初始化数据库
#-*-coding:utf-8 -*- from flask import Flask, render_template, request, jsonify import os import json from models import models from analysis import preprocessing, statistic, LightProcessing from datetime import datetime app = Flask(__name__) APP_ROOT = os.path.dirname(os.path.abspath(__file__)) port = int(os.getenv('PORT', 8000)) db = models.init_db() @app.route('/') def home(): return render_template('index.html') @app.route('/record') def record(): return render_template('record.html') @app.route('/tableau') def tableau(): return render_template('tableau.html') @app.route('/upload_page')
from fastapi import FastAPI from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from models import models, schema app = FastAPI() engine = create_engine('sqlite:///ifa.sqlite') models.init_db(engine) """ Session = sessionmaker(bind=engine, autocommit=True, autoflush=True) session = Session() """ db_session = scoped_session( sessionmaker(bind=engine, autocommit=False, autoflush=False)) @app.get("/products") def get_all_products(): """ Retrieve all products """ products = db_session.query(models.Product).all() return products @app.get("/product/{product_id}") def get_product(product_id: int): product = db_session.query(models.Product).get(product_id) return product
from app import create_app from flask_script import Manager from models.models import init_db import sys app = create_app() if __name__ == '__main__': init_db() reload(sys) sys.setdefaultencoding('utf8') manager = Manager(app) @manager.command def develop(): app.run(host='0.0.0.0', port=8080, debug=True) @manager.command def product(): app.run(host='0.0.0.0', port=80, debug=False) manager.run()