我将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,我不确定我缺少了什么? 谢谢
好的,这样可以-重写规则^http://%{http\u HOST}%{REQUEST\u URI}[END,NE]
诀窍是找出要更新的.htaccess
转到您站点的根public_html。现在,您将在应用程序的名称中找到一个新目录。转到该子目录并在该位置编辑.htaccess文件。这个文件已经有了关于python配置的规则。只需在底部添加以下内容-
将更新保存到.htaccess即可
我知道,/inplay路径不是这样工作的。我也在努力寻找一种工作方式。所有的在线信息都只是简单的hello world示例,这太没用了。Phusion passenger应该发布一些好的示例,这样人们就可以理解,与使用gunicorn nginx等相比,在Cpanel上构建一个好的python示例是多么容易(这在访问受限的web托管服务器上可能是不可能的)。请分享,如果你发现如何路由其他路径,甚至使用它的模板,静态结构
相关问题 更多 >
编程相关推荐