-
-
Save AbreuY/44a938e438b001a7e3e1593534589e13 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