【发布时间】:2016-05-02 00:00:31
【问题描述】:
这对我来说绝对是一个新领域,我只是对它的工作原理感到困惑
烧瓶服务器
$ more flask-hello-world.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return render_template('index.html') #"Hello World!"
if __name__ == "__main__":
app.run()
index.html
$ more index.html
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
</head>
<body>
Hello worlds
</body>
</html>
测试
$ curl 127.0.0.1:5000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
当我return "Hello World!" 时,它确实可以正常工作。为什么我在尝试return render_template('index.html') 时会收到错误消息?
【问题讨论】:
-
您能分享一下您的项目结构吗?
-
我也试过了,所有文件都在同一个文件夹中......实际上这很可能是问题......
标签: python python-2.7 flask