簡體   English   中英

Python WSGI + Flask render_template-500內部服務器錯誤?

[英]Python WSGI + Flask render_template - 500 Internal Server Error?

我有這個結構,

index.py
run.py
app/
  __init__.py
  routes.py
  templates/
    ...

index.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

run.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')

app / __init__.py

(blank)

因此,當我使用/訪問應用程序時,會得到正確的Hello World ,而/dave則會顯示Hello World - From Dave

但是使用/home/about ,我得到500 Internal Server Error

日志文件根本沒有提供有關該錯誤的太多信息,

[2015年8月21日星期五:19:47:06.992431] [mpm_winnt:notice] [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:使用Python / 2.7.10運行時。 [2015年8月21日星期五19:47:07.273231] [mpm_winnt:notice] [pid 5872:tid 244] AH00354:孩子:啟動了64個工作線程。

但是似乎Flask中的模塊render_template沒有加載或無法正常工作。

任何想法我做錯了什么?

Flask默認在應用程序的根路徑下為“ templates”文件夾。

給定您現有的設置,您可以在run.py實例化您的Flask應用程序:

project_root = os.path.dirname(__file__)
template_path = os.path.join(project_root, 'app/templates')
app = Flask(__name__, template_folder=template_path)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM