首页 > 解决方案 > 尽管没有错误,但 Flask 应用程序未呈现 html 页面

问题描述

只是得到一个没有错误的白色空白屏幕。我在 Pycharm 中尝试过,那里没有问题,只有在 VS Code 中

烧瓶 app.py:

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def index():
        return render_template('index.html')


app.run(
        port=5000,
        debug=True
)

HTML:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    Hello World!
</body>
</html>

我正在尝试使用以下地址访问我的页面:http: //127.0.0.1 :5000/

以下是它在浏览器中的样子:[1]:https ://i.stack.imgur.com/to4X9.png

标签: pythonhtmlflask

解决方案


你试过添加这个吗?或者您正在使用另一个文件来运行您的应用程序?

if __name__ == '__main__':
  app.run(
      port=5000,
      debug=True)

推荐阅读