Skip to content

Instantly share code, notes, and snippets.

@souzaux
Forked from maximebf/gist:3986583
Created August 19, 2016 02:32
Show Gist options
  • Select an option

  • Save souzaux/941b568d61fceee1a4f88a37b9760c1e to your computer and use it in GitHub Desktop.

Select an option

Save souzaux/941b568d61fceee1a4f88a37b9760c1e to your computer and use it in GitHub Desktop.
Add dynamic subdomain support to a Flask app
def add_subdomain_to_global(endpoint, values):
g.subdomain = values.pop('subdomain', None)
def add_subdomain_to_url_params(endpoint, values):
if not 'subdomain' in values:
values['subdomain'] = g.subdomain
def add_subdomain_support(app):
app.url_value_preprocessor(add_subdomain_to_global)
app.url_defaults(add_subdomain_to_url_params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment