【发布时间】:2015-06-10 10:30:15
【问题描述】:
我有一个使用 render_template 的烧瓶网络应用程序,如下所示。我需要在响应中添加一个 Content-Security-Policy 作为附加的 http 响应标头。我尝试了以下方法,但都失败并给了我 500。
1.
from flask import \
Flask, \
render_template
app = Flask(__name__,template_folder='tmpl')
@app.route('/')
def index():
resp =make_response(render_template('index.html'))
resp.headers['Content-Security-Policy']='default-src \'self\''
return resp
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3001)
2.
@app.route('/')
def index():
resp =render_template('index.html')
resp.headers.add('Content-Security-Policy','default-src \'self\'')
return resp
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3001)
这里有什么问题?
当我以 localhost:3001 身份访问 Web 应用程序时,我在终端上看到以下内容
127.0.0.1 - - [06/Apr/2015 01:45:01] "GET / HTTP/1.1" 500 -
【问题讨论】: