Created
October 19, 2015 09:18
-
-
Save shnjp/fe6cdc22e2631cb8c7c7 to your computer and use it in GitHub Desktop.
flask's url_for with _scheme overwrite app's default scheme bug
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
# -*- coding: utf-8 -*_ | |
from flask import Flask, url_for | |
def test(): | |
# Building test app. | |
app = Flask('test') | |
app.config['SERVER_NAME'] = 'localhost' | |
@app.route('/') | |
def index(): | |
return 'index' | |
@app.route('/test') | |
def test_view(): | |
return 'testtesttest' | |
with app.test_request_context('/'): | |
url = url_for('test_view') | |
print(url) # /test | |
url = url_for('test_view', _external=True) | |
print(url) # http://localhost/test | |
url = url_for('test_view', _scheme='ws', _external=True) | |
print(url) # ws://localhost/test | |
url = url_for('test_view', _external=True) | |
print(url) # bad ws://localhost/test (expect: http://localhost/test) | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment