【发布时间】:2020-05-04 11:48:13
【问题描述】:
我将flask 与passenger_wsgi 一起使用,我只能让默认的“/”路线工作,所以我的app.py 看起来像:
import os
from flask import Flask, request, render_template, redirect, url_for
project_root = os.path.dirname(os.path.realpath('__file__'))
template_path = os.path.join(project_root, 'app/templates')
static_path = os.path.join(project_root, 'app/static')
app = Flask(__name__, template_folder=template_path, static_folder=static_path)
@app.route('/')
def index():
return 'Hello, World'
@app.route('/inplay')
def getInPlay():
return 'This is a test'
if __name__ == '__main__':
app.run()
passenger_wsgi.py 看起来像
import os
import sys
import importlib.util
sys.path.insert(0, os.path.dirname(os.path.realpath('__file__')))
spec = importlib.util.spec_from_file_location("wsgi", "app.py")
wsgi = importlib.util.module_from_spec(spec)
spec.loader.exec_module(wsgi)
application = wsgi.app
如果我最后只使用 api/ 访问我的 url,它可以工作并显示 hello world,如果我执行 api/inplay it 404s,不确定我错过了什么? 谢谢
【问题讨论】:
-
我有一个类似的问题,只有根 URL 可以工作,所有其他路由都返回 404。将以下内容添加到 .htaccess 文件的顶部:
RewriteEngine onRewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]从以下位置获取此信息: [stackoverflow.com/a/63971427/10122266]
标签: python flask passenger wsgi