本文介绍了Flask url_for生成http URL而不是https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



<$ c $ 使用 url_for 来生成重定向网址。但是,当我将页面改为 时, https 连接时, url_for 仍然会给我 。

我想明确要求 url_for 在网址的开始处添加 https

你能指出我如何改变它吗?



谢谢。

解决方案

使用Flask 0.10,将会有比包装 url_for 更好的解决方案。如果您查看 ,已添加 _scheme 参数。这意味着您可以执行以下操作:

  url_for('secure_thingy',_external = True,_scheme ='https',viewarg1 = 1,...)


I an using url_for to generate redirect url when a user has logged out.

return redirect(url_for('.index', _external=True))

However when I changed the page to a https connection, the url_for still gives me http.

I would like to explicitly ask url_for to add https at the beginning of an url.

Can you point me how to change it? I look at Flask docs, without luck.

Thanks.

解决方案

With Flask 0.10, there will be a much better solution available than wrapping url_for. If you look at https://github.com/mitsuhiko/flask/commit/b5069d07a24a3c3a54fb056aa6f4076a0e7088c7, a _scheme parameter has been added. Which means you can do the following:

url_for('secure_thingy', _external=True, _scheme='https', viewarg1=1, ...)

这篇关于Flask url_for生成http URL而不是https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 04:58