Created
August 3, 2017 09:01
-
-
Save johnsardine/358f48e2d9a0f6da677dda09fe7d98d8 to your computer and use it in GitHub Desktop.
Force Flask url_for to use domain name (absolute url)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In manage.py add | |
# Make sure you import: from flask import url_for | |
@app.context_processor | |
def override_url_for(): | |
return dict(url_for=external_url_for) | |
def external_url_for(endpoint, **values): | |
# Force absolute url in assets | |
if app.config.get('FORCE_EXTERNAL_URL'): | |
values['_external'] = True | |
return url_for(endpoint, **values) | |
# In config.py add | |
# Make sure you import: import os | |
FORCE_EXTERNAL_URL = \ | |
os.environ.get("FORCE_EXTERNAL_URL", "False") == "True" | |
# In your .env add | |
FORCE_EXTERNAL_URL="True" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment