You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.7 KiB
47 lines
1.7 KiB
from quart import Quart, render_template, request, jsonify,send_from_directory,session,redirect, url_for
|
|
from quart_session import Session
|
|
from .main import main
|
|
from .API import api
|
|
from functools import wraps
|
|
|
|
from quart_sqlalchemy import SQLAlchemy
|
|
from flask_migrate import Migrate
|
|
|
|
|
|
#app.config['SECRET_KEY'] = 'mysecret' #密钥 --需要放配置文件
|
|
#socketio = SocketIO(app)
|
|
|
|
def create_app():
|
|
app = Quart(__name__)
|
|
#相关配置--设置各种配置选项,这些选项会在整个应用程序中被访问和使用。
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.config['SECRET_KEY'] = 'zfxxkj_2024_!@#'
|
|
|
|
app.config['SESSION_TYPE'] = 'redis' # session类型
|
|
app.config['SESSION_FILE_DIR'] = './sessions' # session保存路径
|
|
app.config['SESSION_PERMANENT'] = True # 如果设置为True,则关闭浏览器session就失效。
|
|
app.config['SESSION_USE_SIGNER'] = False # 是否对发送到浏览器上session的cookie值进行加密
|
|
Session(app)
|
|
|
|
#ORM数据库管理
|
|
# db = SQLAlchemy()
|
|
# migrate = Migrate()
|
|
# db.init_app(app)
|
|
# migrate.init_app(app, db) # 创建对象,使用它来将ORM模型映射到数据库 -- 效果是及时更新数据的修改到文档?
|
|
|
|
# 注册main
|
|
app.register_blueprint(main)
|
|
#注册API模块
|
|
app.register_blueprint(api,url_prefix = '/api')
|
|
return app
|
|
|
|
|
|
def login_required(f):
|
|
@wraps(f)
|
|
async def decorated_function(*args, **kwargs):
|
|
if 'user' not in session:
|
|
return redirect(url_for('main.login'))
|
|
return await f(*args, **kwargs)
|
|
return decorated_function
|
|
|
|
|