Flask Redirection with Gunicorn & nginx



我的烧瓶显示出奇怪的重定向行为。我不知道我做错了什么。如果我将它们作为'/' route加载,我的所有html files都可以正常工作,但重定向不起作用,并且收到以下错误消息:

ERR_NAME_NOT_RESOLVED
DNS address could not be found

也可以使用以下 4 条路由重现该错误:

@app.route('/')
def index():
return 'The index page'
@app.route('/projects/')
def projects():
return 'The project page'
@app.route('/about')
def about():
return 'The about page'
@app.route('/main')
def main():
return 'The main page'

当在浏览器中仅键入服务器 ip 时,没有 1 将起作用。

没有 2 会像这样工作:ip/项目/但不像这个 ip/项目

No 3 是这样的工作:ip/about,但不像这个ip/about/

4号根本不起作用!为什么?

我是以nginx为代理的runnung gunicorn。提前非常感谢!

从路由的角度来看,/abc//abc是两条不同的路由。但你总是可以告诉烧瓶,那不是你想要的。您可以在代码中对应用程序对象进行全局更改

app.url_map.strict_slashes = False

或者,您可以使用strict_slashes=False对此类行为进行route基本映射

@app.route('/projects/', strict_slashes=False)
def projects():
return 'The project page'

现在#4可能由于方法名称而不起作用。所以改变

@app.route('/main')
def main():
return 'The main page'

@app.route('/main')
def main_route():
return 'The main page'

相关内容

最新更新