Flask subdomain variable not captured, other routes 404

flask, python

Solution

You need to include the port number in your `SERVER_NAME` config.

app.config['SERVER_NAME'] = 'example.com:5000'

Should fix it.

Problem

I'm trying to use Flask's subdomain parameter, but having some trouble. I've configured my local /etc/hosts/ file to point example.com and blog.example.com to 127.0.0.1. For the '`index`' route the subdomain parameter doesn't get captured when I browse to http://blog.example.com:5000. When I try to print `var` it prints "var is ". The '`login`' route 404s, but I can't figure out why. Any help would be greatly appreciated! ``` from flask import Flask app = Flask(__name__) app.debug=True app.config['SERVER_NAME'] = 'example.com' # prints "var is <invalid>" @app.route('/', subdomain="<var>", methods=['GET']) def index(var): print "var is %s" % var return "Hello World %s" % var # This 404s @app.route('/login/', methods=['GET']) def login(): return "Login Here!" if __name__ == '__main__': app.run(host='example.com', debug=True) ```

Original source