我正在努力:http://flask.pocoo.org/docs/1.0/tutorial/
我已经在/flaskr/目录中编写了__init__.py
(代码在这里:http://codepad.org/4FGIE901),设置了一个名为“venv”的虚拟环境并安装了Flask。
然后,我在命令行上在flaskr目录中运行了这些命令-如``运行应用程序''建议:(export FLASK_APP=flaskr
,export FLASK_ENV=development
,flask run
)
我应该看到的是Hello, World!
相反,我看到了以下错误:
Traceback (most recent call last):
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 330, in __call__
rv = self._load_unlocked()
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 246, in locate_app
'Could not import "{name}".'.format(name=module_name)
flask.cli.NoAppException: Could not import "flaskr.flaskr".
简而言之,我不确定应该如何应对或解决此类错误。也许我在venv中安装了什么以及这个特定项目需要什么?
像这个人一样:Could not Import Pandas: TypeError
flask :
/Users/David/Desktop/flaskr/venv/bin/Flask
点数:
from /Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages (python 3.6)
Python:
/Users/David/Desktop/flaskr/venv/bin/python
最佳答案
我认为您在错误的文件夹中。您可能做到了:
cd flask_tutorial/flaskr
您需要进入tutorial文件夹:
cd ..
您应该在
flask run
文件夹中而不是flask_tutorial
中使用flask_tutorial/flaskr
,因为您想从该文件夹中导入flaskr
,而不是flaskr/flaskr
(不存在)。关于python - flask.cli.NoAppException : Could not import “flaskr.flaskr” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50574293/