我一直在尝试遵循[http://flask.pocoo.org/docs/1.0/cli/]的Flask教程,但我无法使Flask运行。
我收到此错误
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 325, in __call__
self._flush_bg_loading_exception()
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 313, in _flush_bg_loading_exception
reraise(*exc_info)
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 302, in _load_app
self._load_unlocked()
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 246, in locate_app
'Could not import "{name}".'.format(name=module_name)
flask.cli.NoAppException: Could not import ""hello.py"".
我尝试过重新安装flask,更改目录并重新启动计算机,但无济于事。
我有一个hello.py,其中包含以下内容
from flask import Flask
app = Flask(__name __)
@app.route('/')
def hello_world():
return 'Hello, World!'
答案 0 :(得分:0)
尝试
将代码放入名为test的文件夹中,在该文件夹中创建一个新的hello.py,将以下代码粘贴到其中
from flask import Flask
app = Flask(__name__) <<<< no space here
@app.route('/')
def hello_world():
return 'Hello, World!'
和cd测试,设置FLASK_APP = hello.py,烧瓶运行对我有用。
答案 1 :(得分:0)
确保在终端中将cd设置为当前项目文件
然后将其输入到终端(使用python代码的文件名代替app.py)