Python 强制Flask在响应中返回HTTP版本
我在某个特定的设备(iPhone SE、iOS 9.3.5)上遇到问题。从另一个角度看,safari似乎认为web服务器使用的是HTTP/0.9,而这个问题可以通过在响应中包含HTTP版本来解决。如果有必要的话,我正在使用模板 我试过这个:Python 强制Flask在响应中返回HTTP版本,python,http,flask,http-headers,Python,Http,Flask,Http Headers,我在某个特定的设备(iPhone SE、iOS 9.3.5)上遇到问题。从另一个角度看,safari似乎认为web服务器使用的是HTTP/0.9,而这个问题可以通过在响应中包含HTTP版本来解决。如果有必要的话,我正在使用模板 我试过这个: @downloader.route('/') def home(): return render_template('home.html', name=get_guest_name()), "HTTP/1.1 200 OK", {"Content-T
@downloader.route('/')
def home():
return render_template('home.html', name=get_guest_name()), "HTTP/1.1 200 OK", {"Content-Type": "text/html"}
但这似乎不起作用。桌面浏览器和其他移动设备工作正常。如果要将
render_template()
结果(即str
)包装在中,请附加所需的标题,例如,沿以下行:
@downloader.route('/')
def home():
resp = make_response(render_template('home.html', name=get_guest_name()))
resp.headers['Content-Type'] = 'text/html'
return resp
您可以将其制作成decorator,使其易于重用。如果要将
render_template()
结果(这是一个str
)包装在中,请附加所需的标题,例如沿以下行:
@downloader.route('/')
def home():
resp = make_response(render_template('home.html', name=get_guest_name()))
resp.headers['Content-Type'] = 'text/html'
return resp
你可以把它做成装饰器,让它易于重复使用