如何让flask python应用程序在没有太多重定向错误的情况下使用heroku重定向到https



我的网站在这里:https://climatebin.herokuapp.com/显示此错误ERR_TOO_MANY_REDIRECTS我尝试删除cookie并转到Firefox,但没有成功。我尝试将URL中的https更改为http,但它一直重定向到https。我没有SSL证书,我在Heroku上使用免费的dynos。我该如何让它发挥作用?

这是我的HTTP到HTTPS重定向代码。

@app.before_request
def before_request():
# this checks if the user requests http and if they did it changes it to https
if request.headers.get('X-Forwarded-Proto') == 'http':
url = request.url.replace('http://', 'https://', 1)
print("redirected to https?")
code = 301
return redirect(url, code=code)

我的网站是动态的,依靠免费的Heroku dynos和SSL来运行。Heroku只为静态网站运行免费的SSL。

最新更新