我得到了一个内部服务器错误,我不知道问题是什么。index.html
与Python位于同一个目录中。
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
author = "Rick"
name = "1st flask app"
return render_template('index.html', author=author, name=name)
if __name__ == "__main__":
app.run()
<!DOCTYPE html>
<html>
<head>
<title>{{ author }}'s app</title>
</head>
<body>
<h2>Hello {{ name }}!</h2>
<p>Please show up on the page</p>
</body>
</html>
为什么我得到一个500错误而不是我呈现的模板?
发布于 2015-04-02 16:46:40
创建一个名为templates
的目录,并将index.html
放入其中。
通过在调试模式下运行,您可以获得有关错误的更多信息:
app.run(debug=True)
发布于 2015-04-02 17:12:05
创建应用程序app = Flask(__name__)
时,还可以包括template_folder
参数,以指定包含模板的文件夹。如果没有,render_template
将在名为templates
的默认文件夹中查找它们。如果不存在这样的文件夹,或者在其中找不到您的模板,您将得到一个内部服务器错误500,而不是您呈现的模板。
https://stackoverflow.com/questions/29417845
复制相似问题