python - 无法导入 "D": FLASK_APP

标签 python user-interface flask cmd

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/

相关文章:

python - 有效地迭代 pandas 行

python - 谷歌应用引擎: receive email then/and forward it?

python - f2py,返回数组的 Python 函数(向量值函数)

java - 如果 setPopupVisible 遵循 setvisible true,则取消 setPopupVisible

python - 将多级多索引名称转换为 DataFrame 列,Python 3.6

java - 子类型 SwingWorker : where would I place my statements that would not run in the GUI thread

python - 我如何使用 tkinter python 与 phrase = input ("ENTER TEXT ") Tkinter 文本框?

python - 在 flask 中创建文件夹

python - 如何在 Flask/Jinja 中选择/减少字典列表

flask - 如何在支持的 SQL alchemy 中存储参数,这些参数将传递给 Flask 应用程序中的 celery 任务