flask的http和https的重定向和https强制使用办法

flask使用https的nginx和flask中的解决办法

Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure form action '<URL>'. This request has been blocked; the content must be served over HTTPS.

解决办法

return redirect(url_for('********', _external=True, _scheme='https'))
加上 _external=True, _scheme=’https 即可

Nginx中这样修改

1
2
3
4
5
server {
listen 80;
server_name ******;
return 301 https://$server_name$request_uri;
}

小伟科技 wechat
python爱好者公众号—每日学习python必备
欢迎打赏支持!