url_for with _external = True在heroku上不附加URL上的服务器名称 [英] url_for with _external=True on heroku doesn't append the server name on 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)))
我的电子邮件是:
的http:/// register_account / DnsJpXw_QIcPYeDHEg_fipB2kRiJBUj2RI6I9cI4Yl4w6K9ohbZRMVqBInuV0aOsBT4Zqt69X8MfhNfnys4s-DAQmgu1OPBwmSQnzAELvdcCyiZtkJGSY8_dQ799FOewtBDkvqR1D8XHmvVxgaVqbwSjdEBnvFsBBHMQCic%3D /验证外部=真
我遇到以下问题:
///
如果服务器名称为空
我应该怎么做才能得到正确的URL https:// my-server-name / register_account ...
?
编辑
我尝试在config.py文件中设置以下变量:
SERVER_NAME = http://my-server-58140.herokuapp.com 它在我的路径中产生了错误,我无法访问任何URL,例如下面的一个可以访问,但是当定义我的 编辑 我的应用程序配置为: 其中environnement变量设置为 请参阅 编辑:此外, 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: But the link I'm receiving in my email is: I have problems with this URL: What should I do to have the correct URL 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 EDIT My flask application is configured: Where the environnement variable is set to To generate the correct URL, these two Flask configuration values need to be set: See the documentation for EDIT: Additionally, the parameter in 这篇关于url_for with _external = True在heroku上不附加URL上的服务器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b 它不再是:
$ 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 __))
0.0.0.0:5000
在我的生产服务器上 my-server-58140.herokuapp.com
SERVER_NAME
添加到您网站的名称中,
PREFERRED_URL_SCHEME
code> https 。
url_for()
和如何配置Flask应用程序。
url_for
中的参数应该是 _external
而不是外部
。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/verify?external=True
///
like if the server name was blankhttps://my-server-name/register_account...
?SERVER_NAME
it didn't anymore: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__))
0.0.0.0:5000
on my localhost and: my-server-58140.herokuapp.com
on my production server
SERVER_NAME
to the name of your website,PREFERRED_URL_SCHEME
to https
.url_for()
and how to configure a Flask application.url_for
should be _external
and not external
.