运行时烧瓶未显示http地址 [英] Flask not displaying http address when I run it

查看:51
本文介绍了运行时烧瓶未显示http地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Flask框架运行Hello World:

I'm trying to run the Hello World using Flask framework :

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello() -> str:
    return 'Hell world from Flask!'
app.run()

然后我进入我的cmd,然后根据文档运行脚本:

Then I go to my cmd and I run my script according to the documentation:

set FLASK_APP = flaskhello.py
python -m flask run 

我得到的是带有单击我标题的灰色窗口,当我单击它时,我得到了X和Y,但是我没有在cmd上获得http地址,无法在浏览器上运行它.我该怎么做才能纠正这个问题?

And what I get is a grey window with a click me header and when I click it i get the X and Y but I don't get the http address on my cmd to run it on browser. What should I do to correct this ?

我似乎已经正确安装了烧瓶,但是不确定.

I've already installed flask correctly as it seems, but I'm not sure.

编辑.我还尝试创建一个新的venv,并且发生了同样的情况

edit. I also tried creating a new venv and the same happens

推荐答案

您正在混合新旧文档.您可能会丢失flaskhello.py( app.run())中的最后一行.然后,不要将 flask run 命令传递给python,而是直接在CMD中运行它.因此,不是 python -m flask运行,而是 flask运行.

You are mixing old and new documentation. You can lose the last line in flaskhello.py (app.run()). Then, don't pass the flask run command to python, but run it directly in the CMD. So not python -m flask run, but flask run.

这篇关于运行时烧瓶未显示http地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆