flask项目目录结构

Demo.py

from apps import create_app

app=create_app()
if __name__== '__main__':
    app.run(app.config['HOST'],app.config['PORT'],app.config['DEBUG'],threaded =False)
 

  

apps/__init__.py

from flask import Flask
from flask import Blueprint
def create_app():
    app = Flask(__name__)
    app.config.from_object("apps.settings")
    register_blueprint(app)
    
    return app
    
def register_blueprint(app):
    from apps.main import web
    app.register_blueprint(web)

  

apps/settings.py

DEBUG = True
HOST = '0.0.0.0'
PORT = 911

  

apps/main/__ini__.py

from flask import Blueprint

web = Blueprint('web', __name__)
@web.app_errorhandler(404)
def not_found(e):
    return '找不到页面'
from . import demo_index 

  

appsmaindemo_index.py

from . import web
@web.route('/')
def index():
    return "Hello World!"

  

原文地址:https://www.cnblogs.com/luoye00/p/14356460.html