flask create_app() 有问题

问题描述 投票:0回答:1

使用flask create_app()似乎不起作用。

下面是我的代码

run.py

from gg import app
if __name__ == '__main__':
   app.run(host='x.x.x.x', port='XXXX', debug=True)

__init__.py

from flask import Flask
app = Flask(__name__)
print("hello1")
def create_app():
   print("hello2")
   return app

在我的控制台上我只收到“hello1” 为什么 create_app 不工作?

而且,当我将 init.py 修复为

from flask import Flask
app = Flask(__name__)
print("hello2")

它给出了无法从gg导入应用程序的错误

激活create_app()有什么帮助吗?

python flask
1个回答
0
投票
from flask import Flask

app = Flask(__name__)

@app.route("/")
def create_app():
   return "hello1"

@app.route("/create_app_1")
def create_app_1():
   return "hello2"



if __name__ == "__main__":
   app.run(host = "0.0.0.0")

'''use this @app.route("/") this navigate to the url,
("/") in this after '/' whatever path you can give
for run create_app :- http://127.0.0.1:5000
and for create_app_1 :- http://127.0.0.1:5000/create_app_1
'''
© www.soinside.com 2019 - 2024. All rights reserved.