【问题标题】:Flask Redirection with Gunicorn & nginx使用 Gunicorn 和 nginx 进行烧瓶重定向
【发布时间】:2017-08-25 22:21:35
【问题描述】:

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

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/projects/ 但不是这样 ip/projects

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

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

我用 nginx 作为代理运行 gunnung gunicorn。非常感谢!

【问题讨论】:

    标签: python nginx flask gunicorn


    【解决方案1】:

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

    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'
    

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2016-08-30
      • 2017-06-06
      • 2014-04-14
      • 1970-01-01
      相关资源
      最近更新 更多