skyler
skyler

Reputation: 8348

Specify port for url_for

How can I specify the port used for the Flask url_for method? Or, can I configure Flask to use whatever port it is running on for url_for? My issue is that I'm running a server on port 8080 but url_for does not add this port to any URLs generated, so any generated URLs use port 80 and do not resolve.

Upvotes: 0

Views: 1562

Answers (1)

skyler
skyler

Reputation: 8348

It seems the only way to specify a port in url_for is to use the _external=True argument like so:

url_for('handle_contact_form', _external=True)

This generates a URL like http://localhost:5000/contact-us. Unfortunately a :5000/contact-us isn't a valid relative URL. So without using a full, external URL, the port cannot be specified.

Upvotes: 1

Related Questions