Skip to content

Instantly share code, notes, and snippets.

@shnjp
Created October 19, 2015 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shnjp/fe6cdc22e2631cb8c7c7 to your computer and use it in GitHub Desktop.
Save shnjp/fe6cdc22e2631cb8c7c7 to your computer and use it in GitHub Desktop.
flask's url_for with _scheme overwrite app's default scheme bug
# -*- 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