Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t使用A2共享主机上的乘客WSGI向Flask添加路由_Python_Flask_Passenger_Wsgi - Fatal编程技术网

Python Can';t使用A2共享主机上的乘客WSGI向Flask添加路由

Python Can';t使用A2共享主机上的乘客WSGI向Flask添加路由,python,flask,passenger,wsgi,Python,Flask,Passenger,Wsgi,我将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/tem

我将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()
乘客_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 404s,我不确定我缺少了什么?
谢谢

据我所知,/inplay路径不是这样工作的。我也在努力寻找一种工作方式。所有的在线信息都只是简单的hello world示例,这太没用了。Phusion passenger应该发布一些好的示例,这样人们就可以理解,与使用gunicorn nginx等相比,在Cpanel上构建一个好的python示例是多么容易(这在访问受限的web托管服务器上可能是不可能的)。如果您知道如何路由其他路径,或者甚至在模板、静态结构上使用它,请务必共享。

好的,这很有效-重写规则^http://%{http\u HOST}%{REQUEST\u URI}[END,NE]

诀窍是找出要更新的.htaccess

转到您站点的根public_html。现在,您将在应用程序的名称中找到一个新目录。转到该子目录并在该位置编辑.htaccess文件。这个文件已经有了关于python配置的规则。只需在底部添加以下内容-

RewriteEngine On
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

将更新保存到.htaccess,就这样。

我遇到了一个类似的问题,只有根URL可以工作,所有其他路由返回404。将以下内容添加到.htaccess文件的顶部:
RewriteEngine on
RewriteRule^http://%{http\u HOST}%{REQUEST\u URI}[END,NE]
从以下位置获取此信息:[我遇到了一个类似的问题,只有根URL可以工作,所有其他路由返回404。请将以下内容添加到.htaccess文件的顶部:
RewriteEngine on
RewriteRule^http://%{http\u HOST}%{REQUEST\u URI}[END,NE]
。从以下站点获取此信息:[.这并不能提供问题的答案。一旦你有了足够的答案,你将能够;相反。