我有这个结构,
index.py
run.py
app/
__init__.py
routes.py
templates/
...
索引.py,
import os
import sys
activate_this = os.path.dirname(__file__) + '/venv/Scripts/activate_this.py'
exec(open(activate_this).read(), dict(__file__ = activate_this))
# Expand Python classes path with your app's path.
sys.path.insert(0, os.path.dirname(__file__))
from run import app
#Initialize WSGI app object.
application = app
运行.py,
from flask import Flask
app = Flask(__name__)
from app import routes
if __name__ == '__main__':
app.run()
应用程序/routes.py,
from run import app
from flask import Flask, render_template
@app.route('/')
def hello_world():
return 'Hello World'
@app.route('/dave')
def myDave():
return 'Hello World - From Dave'
@app.route('/home')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
应用程序/
__init__.py
,(blank)
所以当我使用
/
访问应用程序时,我得到Hello World
这是正确的,并且/dave
我得到Hello World - From Dave
但是使用
/home
和/about
,我得到500个内部服务器错误日志文件根本没有提供关于错误的太多信息,
【2015年8月21日星期五19:47:06.992431】【mpm_winnt:通知】【pid 7036:tid】
244]AH00418:父进程:已创建子进程5872[8月21日星期五]
19:47:07.257631 2015][wsgi:warn][pid 5872:tid 244]mod_wsgi:
为Python/2.7.9+编译。【2015年8月21日星期五19:47:07.257631】
[wsgi:warn][pid 5872:tid 244]mod_wsgi:Runtime使用Python/2.7.10。
【2015年8月21日星期五19:47:07.273231】【mpm_winnt:通知】【pid 5872:tid】
244]AH00354:子线程:启动64个工作线程。
但似乎烧瓶的模块
render_template
未加载或不工作。你知道我做错了什么吗?
最佳答案
Flask默认为应用程序根路径上的“templates”文件夹。
给定您现有的设置,您可以在run.py
中实例化您的烧瓶应用程序。
project_root = os.path.dirname(__file__)
template_path = os.path.join(project_root, 'app/templates')
app = Flask(__name__, template_folder=template_path)
关于python - Python WSGI + Flask render_template-500内部服务器错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32140116/