[英](FLASK) I can't figure out why my html file doesn't update/render
[英]Why it can't render html file in Flask?
from flask import Flask, render_template
skills_app = Flask(__name__)
@skills_app.route("/")
def homepage():
return render_template("homepage.html")
if __name__ == "__main__":
skills_app.run()
现在主页.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
Hello from Html page
</body>
</html>
但是当我运行我的页面时,“来自 HTML 页面的你好”没有出现,是的,我创建了模板文件夹并将 homepage.html 放入其中。 那么这里有什么问题呢? 你可以帮帮我吗
默认情况下,Flask 会查找要渲染的templates
目录。 如果你想让你的代码工作,在你的主文件旁边创建一个模板文件夹,把 homepage.html 放在里面。
或者,初始化应用程序,例如,
skills_app = Flask(__name__, templates='/path/to/directory/containing/html-files')
并将您的模板放入/path/to/directory/containing/html-files
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.