Skip to content

Instantly share code, notes, and snippets.

@justinfay
Created June 19, 2013 13:36
Show Gist options
  • Save justinfay/5814382 to your computer and use it in GitHub Desktop.
Save justinfay/5814382 to your computer and use it in GitHub Desktop.
from flask import Flask
app = Flask(__name__)
app.config['SERVER_NAME'] = 'flasksubs.local:5000'
app.config['SUB_DOMAINS'] = {
'good': 'good sub domain',
'ok': 'ok sub domain'
}
app.config['NO_SUB_DOMAIN_MSG'] = 'no sub domain found'
@app.route("/", defaults={'subdomain': ''})
@app.route("/", subdomain='<subdomain>')
def subdomain_message(subdomain):
if not subdomain:
msg = 'This is the root url'
else:
msg = app.config['SUB_DOMAINS'].get(subdomain)
if msg is None:
msg = app.config['NO_SUB_DOMAIN_MSG']
return msg
if __name__ == '__main__':
app.run(port=5000, debug=True)
127.0.0.1 flasksubs.local
127.0.0.1 good.flasksubs.local
127.0.0.1 ok.flasksubs.local
127.0.0.1 bad.flasksubs.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment