【发布时间】:2015-04-26 03:46:45
【问题描述】:
我的 Python 应用程序的“静态”路由规则在我的 AWS Elastic Beanstalk 应用程序中表现异常(其他任何地方都没有),似乎覆盖了所有其他规则。
例如,使用下面的两个函数,在我的开发机器和其他地方的测试服务器以及 AWS 上,routes 将静态规则列在最后,match_route 显示其他非静态规则匹配以 ' 开头的路径静止的/...'。正如预期的那样,如果我在我的非 AWS 机器上导航到路径以 static/... 开头的页面,则匹配我的其他(非静态)规则之一。但是(仅)在 AWS-EB 上,会为此类路径调用服务器的静态规则!
AWS-EB 为什么以及如何在所有其他规则之前“插入”这条规则?如何在 AWS 上禁用此行为,或在我的非 AWS 系统中复制它?
application.url_map.host_matching = True
# ...
def routes(verbose, wide):
"""List routes supported by the application"""
for rule in sorted(app.url_map.iter_rules()):
if verbose:
fmt = "{:45s} {:30s} {:30s}" if wide else "{:35s} {:25s} {:25s}"
line = fmt.format(rule, rule.endpoint, ','.join(rule.methods))
else:
fmt = "{:45s}" if wide else "{:35s}"
line = fmt.format(rule)
print(line)
def match_route(host, match):
"""Match a route for a given host"""
if match is not None:
urls = app.url_map.bind(host)
try:
m = urls.match(match, "GET")
z = '{}({})'.format(m[0], ','.join(["{}='{}'".format(arg, m[1][arg]) for arg in m[1]] +
["host='{}'".format(host)]))
return z
except NotFound:
return
【问题讨论】:
标签: amazon-web-services flask url-routing amazon-elastic-beanstalk werkzeug