Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url_for with _external=True on heroku doesn't append the server name on the URL

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

like image 434
mel Avatar asked Jun 29 '17 04:06

mel


1 Answers

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.

like image 100
Bovarysme Avatar answered Nov 07 '22 18:11

Bovarysme