我正在尝试使用Flask的子域参数,但遇到了一些问题。
我已经配置了本地的/etc/hosts/文件,将example.com和blog.example.com指向127.0.0.1。
在“index”路由中,当我浏览http://blog.example.com:5000时,子域参数不会被捕获。 当我尝试打印“var”时,它打印“var is”。
“login”路由返回404错误,但我无法找出原因。非常感谢您的帮助!
我已经配置了本地的/etc/hosts/文件,将example.com和blog.example.com指向127.0.0.1。
在“index”路由中,当我浏览http://blog.example.com:5000时,子域参数不会被捕获。 当我尝试打印“var”时,它打印“var is”。
“login”路由返回404错误,但我无法找出原因。非常感谢您的帮助!
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)