Flask redirect returns wrong URL

I have simple flask test script:

from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired
from flask import Flask, request, render_template,redirect

app = Flask(__name__)

def index():
    return redirect('success')

def success():
    return render_template('f2.html')

When I enter the site on: https://dashboard-3kt3.onrender.com
I get redirectired to: https://srv-c62hvmc6fj3eaf4oprt0-kn.usr-c62h643ru51hm0sjfm2g.onrender.com/success
And thus get error

Can you please help me how to correct this?

Thank you.

Hi @Petr, welcome to the Render community!

Thank you for reporting this issue! We’re currently investigating this on our end.

Hi @Petr, it looks like this has to do with how we are handling the headers. The issue looks to be isolated to the Free plan. We’re investigating a long-term fix. In the meantime, you may be able to workaround this by adding proxyfix in your app like so:

from flask import Flask, redirect
from werkzeug.middleware.proxy_fix import ProxyFix

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_host=1, x_proto=1)

Let me know if it helps!

Hello @Jade_Paoletta,
I upgraded to paid plan and the error is fixed now. This works for me as I was planning to use your paid plan anyway. Thank you for the info.

1 Like

Hey! We pushed a fix out this morning. Would you mind giving it another try on the free plan?

I tried on free plan and everything is working fine now. Thank you!

1 Like