我是Flask的新手(也是python的新手),我尝试运行以下非常基本的脚本:
from flask import Flask
app= Flask(__name__)
@app.route('/')
def home():
return "This is the homepage"
if __name__=="__main__":
app.run(debug=True)
我在Windows 10上使用Python 3.6和IDLE。 问题是我一直收到以下错误:
Traceback (most recent call last):
File "C:/Users/Susy/Desktop/provaflask.py", line 7, in <module>
app.run(debug=True)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 936, in run
cli.show_server_banner(self.env, self.debug, self.name, False)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\cli.py", line 630, in show_server_banner
click.echo(message)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\utils.py", line 217, in echo
file = _default_text_stdout()
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\_compat.py", line 621, in func
rv = wrapper_func()
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\_compat.py", line 385, in get_text_stdout
rv = _get_windows_console_stream(sys.stdout, encoding, errors)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\_winconsole.py", line 261, in _get_windows_console_stream
func = _stream_factories.get(f.fileno())
io.UnsupportedOperation: fileno
来自this question,问题似乎与IDLE的使用有关,但是我想继续使用它,所以你能帮忙吗?谢谢!
答案 0 :(得分:2)
你可以找到here 你必须从直接运行Python脚本。
您必须在app.py
中保存该文件
并从命令行运行:
python app.py
或在您的例子中:
python C:/Users/Susy/Desktop/provaflask.py