<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[吉凯]项目初始化代码参考]]></title><description><![CDATA[<p dir="auto"><a href="http://an.forum.genostack.com/topic/952/%E5%90%89%E5%87%AF-%E5%85%B3%E4%BA%8E%E6%A8%A1%E6%9D%BF%E9%A1%B9%E7%9B%AE%E7%9A%84%E8%AF%B4%E6%98%8E">返回</a></p>
<h1><code>app/__init__.py</code>代码中涉及的需求汇总</h1>
<ul>
<li>动态注册蓝图</li>
<li>一些参数有默认的配置</li>
<li>增加version的识别（可优化）</li>
<li>增加对前端 <code>/tool_detail</code> 路由的支持</li>
</ul>
<pre><code class="language-python">#!/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

</code></pre>
]]></description><link>http://an.forum.genostack.com/topic/951/吉凯-项目初始化代码参考</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 09:37:45 GMT</lastBuildDate><atom:link href="http://an.forum.genostack.com/topic/951.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Jul 2023 09:49:51 GMT</pubDate><ttl>60</ttl></channel></rss>