I am using url_for
to generate a redirect URL when a user has logged out:
return redirect(url_for(\'.index\', _external=True))
Setting _scheme
on every url_for()
call is extremely tedious, and PREFERRED_URL_SCHEME
doesn't seem to work. However, mucking with what the request's supposed scheme is at the WSGI level seems to successfully convince Flask to always construct HTTPS URLs:
def _force_https(app):
def wrapper(environ, start_response):
environ['wsgi.url_scheme'] = 'https'
return app(environ, start_response)
return wrapper
app = Flask(...)
app = _force_https(app)