返回
app/__init__.py代码中涉及的需求汇总
- 动态注册蓝图
- 一些参数有默认的配置
- 增加version的识别(可优化)
- 增加对前端
/tool_detail 路由的支持
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@Author : ice-melt@outlook.com
@File : __init__.py.py
@Time : 2022/09/21
@Version : 1.0
@Desc : None
"""
import importlib
import logging
import os
from app.utils import Paths
from ms_jk_utils.web import blueprints_dynamic_register
from ms_jk_utils.cfg import DefaultConfig
from flask_cors import CORS
from flask import Flask, g, render_template
__VERSION = (1, 0, 0)
__VERSION__ = ".".join(map(lambda x: str(x), __VERSION))
def create_app():
app = Flask(__name__,
static_folder="../dist/static",
template_folder="../dist",
instance_path=Paths.instance_path)
print(app.instance_path)
print(app.static_folder)
print(app.template_folder)
# r'/*' 是通配符,让本服务器所有的URL 都允许跨域请求
CORS(app, resources=r'/*')
app.config.from_object(DefaultConfig)
app.config.from_pyfile(os.path.join(app.instance_path, 'config.py'))
app.config["version"] = __VERSION__
blueprints_dynamic_register(os.path.dirname(__file__), app)
# views_bp.before_request(check_ticket)
# r'/*' 是通配符,让本服务器所有的URL 都允许跨域请求
CORS(app, resources=r'/*')
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@app.route('/tool_detail', methods=['GET'])
def tool_detail():
return render_template('index.html')
# @app.route('/static', methods=['GET'])
# def static():
# return render_template('index.html')
return app