greyli / helloflask

Hello, Flask!
https://docs.helloflask.com
MIT License
1.87k stars 2.53k forks source link

运行http示例程序报错,不知如何解决。 #129

Closed Pengwu96 closed 5 years ago

Pengwu96 commented 5 years ago

working directory: /Users/myname/Documents/GitHub/helloflask/demos/http 已重新安装flask( pipenv install flask 和 pipenv update flask) 问题依旧。 之前在第一章的时候的目录里的实例程序都可以跑起来,到了第二章的实例程序就出问题了。

/Users/myname/.local/share/virtualenvs/helloflask-VOwUqXuy/bin/python -m flask run

http://127.0.0.1:5000/

flask.cli.NoAppException

flask.cli.NoAppException: Could not import "app". Traceback (most recent call last)

File "/Users/myname/.local/share/virtualenvs/helloflask-VOwUqXuy/lib/python3.7/site-packages/flask/cli.py", line 330, in __call__

rv = self._load_unlocked()

File "/Users/myname/.local/share/virtualenvs/helloflask-VOwUqXuy/lib/python3.7/site-packages/flask/cli.py", line 317, in _load_unlocked

self._app = rv = self.loader()

File "/Users/myname/.local/share/virtualenvs/helloflask-VOwUqXuy/lib/python3.7/site-packages/flask/cli.py", line 372, in load_app

app = locate_app(self, import_name, name)

File "/Users/myname/.local/share/virtualenvs/helloflask-VOwUqXuy/lib/python3.7/site-packages/flask/cli.py", line 246, in locate_app

'Could not import "{name}".'.format(name=module_name)

flask.cli.NoAppException: Could not import "app".

The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.

Pengwu96 commented 5 years ago

我后来找到解决方法了。在Pycharm CE 里,用菜单栏的file--New Project,在新的文件夹里,重新生成一个项目,再把原来的文件,复制到新的项目的文件夹里,再重新运行,就可以了。

scottming commented 5 years ago

Mark directory as sourceroot.