0
我的Flask應用程序將http重定向到https。我發現 python flask redirect to https from http但它不起作用。如何在http中重定向http到https
from flask import Flask, request, redirect
from werkzeug.serving import make_ssl_devcert
make_ssl_devcert('key')
app = Flask(__name__)
@app.before_request
def before_request():
if request.url.startswith('http://'):
url = request.url.replace('http://', 'https://', 1)
code = 301
return redirect(url, code=code)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(host='127.0.0.1', port=443, debug=False, ssl_context=('key.crt', 'key.key'))