url_for with _external = True在heroku上不附加URL上的服务器名称 [英] url_for with _external=True on heroku doesn't append the server name on the URL

查看:820
本文介绍了url_for with _external = True在heroku上不附加URL上的服务器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  content = Content(text / html,verification_email.format(user [first_name],
url_for(register.display_register_form,
token = token.decode utf-8),external = True)))

我的电子邮件是:

 的http:/// register_account / DnsJpXw_QIcPYeDHEg_fipB2kRiJBUj2RI6I9cI4Yl4w6K9ohbZRMVqBInuV0aOsBT4Zqt69X8MfhNfnys4s-DAQmgu1OPBwmSQnzAELvdcCyiZtkJGSY8_dQ799FOewtBDkvqR1D8XHmvVxgaVqbwSjdEBnvFsBBHMQCic%3D /验证外部=真

我遇到以下问题:


  • 它不是https,应该是因为它是在heroku上的主机

  • 服务器名称没有ar只在URL中 /// 如果服务器名称为空



我应该怎么做才能得到正确的URL https:// my-server-name / register_account ...



编辑



我尝试在config.py文件中设置以下变量:

SERVER_NAME = http://my-server-58140.herokuapp.com
$ b

它在我的路径中产生了错误,我无法访问任何URL,例如下面的一个可以访问,但是当定义我的它不再是:

$ p $ http:// my-server-58140 .herokuapp.com / home

编辑

我的应用程序配置为:

  SERVER_NAME = os.environ.get('SERVER_NAME') 
DEBUG = True
BASE_DIR = os.path.abspath(os.path.dirname(__ file __))

其中environnement变量设置为 0.0.0.0:5000 在我的生产服务器上 my-server-58140.herokuapp.com




  • > SERVER_NAME 添加到您网站的名称中,
  • PREFERRED_URL_SCHEME code> https



请参阅 url_for() 如何配置Flask应用程序



编辑:此外, url_for 中的参数应该是 _external 而不是外部


I have deploy an application on Heroku but the problem is when my application send email it doesn't append the name of my server in the URL:

content = Content("text/html", verification_email.format(user["first_name"],
                                                             url_for("register.display_register_form",
                                                                     token=token.decode("utf-8"), external=True)))

But the link I'm receiving in my email is:

http:///register_account/DnsJpXw_QIcPYeDHEg_fipB2kRiJBUj2RI6I9cI4Yl4w6K9ohbZRMVqBInuV0aOsBT4Zqt69X8MfhNfnys4s-DAQmgu1OPBwmSQnzAELvdcCyiZtkJGSY8_dQ799FOewtBDkvqR1D8XHmvVxgaVqbwSjdEBnvFsBBHMQCic%3D/verify?external=True

I have problems with this URL:

  • It is not https and it should be since it's host on heroku
  • The server name doesn't appear in the URL only /// like if the server name was blank

What should I do to have the correct URL https://my-server-name/register_account...?

EDIT

I tried to set in my config.py file with the following variable to:

SERVER_NAME = "http://my-server-58140.herokuapp.com"

It generated errors in my path and I couldn't access any URL for example, the following one could be access before but when defining my SERVER_NAME it didn't anymore:

http://my-server-58140.herokuapp.com/home

EDIT

My flask application is configured:

SERVER_NAME = os.environ.get('SERVER_NAME')
DEBUG = True
BASE_DIR = os.path.abspath(os.path.dirname(__file__))

Where the environnement variable is set to 0.0.0.0:5000 on my localhost and: my-server-58140.herokuapp.com on my production server

解决方案

To generate the correct URL, these two Flask configuration values need to be set:

  • SERVER_NAME to the name of your website,
  • and PREFERRED_URL_SCHEME to https.

See the documentation for url_for() and how to configure a Flask application.

EDIT: Additionally, the parameter in url_for should be _external and not external.

这篇关于url_for with _external = True在heroku上不附加URL上的服务器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆