gpt4 book ai didi

python - 无法导入 "D": FLASK_APP

转载 作者:行者123 更新时间:2023-11-28 17:03:47 25 4
gpt4 key购买 nike

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello, World!'

我是 Flask 的新手。我编写了这段基本代码并将其保存在我的 D:\Cat_vs_Dog\scripts 文件夹中的 hello.py 中。

然后在命令提示符下,我写了以下命令。

C:\Users\Ketan Ingale>set FLASK_APP=D:\Cat_vs_Dog\scripts\hello.py

C:\Users\Ketan Ingale>flask run
* Serving Flask app "D:\Cat_vs_Dog\scripts\hello.py"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not import "D".

我遇到了这个错误。我该怎么办...?

最佳答案

flask v1.1.x

https://flask.palletsprojects.com/en/1.1.x/cli/#application-discovery

以上文档链接描述:

The flask command is installed by Flask, not your application; it must be told where to find your application in order to use it. The FLASK_APP environment variable is used to specify how to load the application.

删除目录并只使用文件名并重试。

您可能需要 CD 到包含您的文件的目录。

flask 2.2.x

https://flask.palletsprojects.com/en/2.2.x/cli/#application-discovery

上面的文档链接指定:

The flask command is installed by Flask, not your application; it must be told where to find your application in order to use it. The --app option is used to specify how to load the application.

还有:

If --app is not set, the command will try to import “app” or “wsgi” (as a “.py” file, or package) and try to detect an application instance or factory.

关于python - 无法导入 "D": FLASK_APP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52581576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com