python - 尽管没有错误,但 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
解决方案
你试过添加这个吗?或者您正在使用另一个文件来运行您的应用程序?
if __name__ == '__main__':
app.run(
port=5000,
debug=True)
推荐阅读
- json - django ajax 内容安全策略指令
- jupyter-notebook - 风筝不在 jupyter 实验室工作,但在 python 工作
- php - PHP & Bootstrap 3 sendmail.php 确认进入引导提示成功或失败消息
- powershell - 添加“获取模块 | 移除模块;Clear-Host' 到包含的 PowerShell 代码
- reactjs - 如何解决 React js 中的解析错误?
- java - 我可以在springboot中轻松重用url路径映射作为设置吗?
- amazon-web-services - 将负载均衡器添加到 Elastic Beanstalk 会导致 502 Bad Gateway
- r - R:如何改变列并将其分组
- java - 我正在阅读“Java 编程和数据结构简介”一书,在解释类抽象和封装的章节中,它说:
- node.js - 如何在 Mongoose 中正确格式化 API 响应?