【发布时间】:2014-08-26 00:44:51
【问题描述】:
我正在尝试提供静态 html 文件,但返回 500 错误 (editor.html 的副本位于 .py 和模板目录中) 这就是我尝试过的全部:
from flask import Flask
app = Flask(__name__, static_url_path='/templates')
@app.route('/')
def hello_world():
#return 'Hello World1!' #this works correctly!
#return render_template('editor.html')
#return render_template('/editor.html')
#return render_template(url_for('templates', filename='editor.html'))
#return app.send_static_file('editor.html') #404 error (Not Found)
return send_from_directory('templates', 'editor.html')
这是回复:
Title: 500 Internal Server Srror
Internal Server Error
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.
【问题讨论】:
-
其他地方有一个不同的错误。您的大多数尝试应该都成功了,但是如果即使只返回一个字符串也失败了,您需要查看控制台并查看抛出了什么错误,或者在调试模式下运行 Flask。
-
很抱歉我忘了删除它,但字符串可以正常工作。
-
你试过
app = Flask(__name__)而不是指定路径吗? -
是的,这是我的第一次尝试,两种方式都返回 404 错误 Not found
-
你是如何运行 WSGI 应用程序的?