Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created June 22, 2012 12:32
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 mitsuhiko/2972483 to your computer and use it in GitHub Desktop.
Save mitsuhiko/2972483 to your computer and use it in GitHub Desktop.
$ python routetest.py
/
>>> group_list(www2)
/aha
>>> jot_list(www2, aha, None)
/aha:blah
>>> jot_list(www2, aha, blah)
from flask import Flask
app = Flask(__name__)
app.config['SERVER_NAME'] = 'lvh.me:5000'
# lvh.me:5000 routes back to localhost so you can test subdomains locally
# with sub.lvh.me:5000
# sub.lvh.me:5000/ should only trigger this group_list route
@app.route('/', subdomain='<area>')
def group_list(area='www', group=None, subgroup=None):
return "group_list(%s)" % area
# but for some reason, this route is also picking it up.
# you can see in the console that both group_list & jot_list run
@app.route('/<group>:<subgroup>', subdomain='<area>')
@app.route('/<group>', subdomain='<area>')
def jot_list(area='www', group='general', subgroup=None):
return "jot_list(%s, %s, %s)" % (area, group, subgroup)
c = app.test_client()
def test(url, subdomain='www2'):
print url
print '>>>', c.get(url, base_url='http://%s.lvh.me:5000/' % subdomain).data
test('/')
test('/aha')
test('/aha:blah')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment