Created
June 19, 2013 13:36
-
-
Save justinfay/5814382 to your computer and use it in GitHub Desktop.
This file contains 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
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) |
This file contains 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
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