[Flask] Templatizing HTTP Response Headers

John Overbaugh joatgm at gmail.com
Thu Nov 17 15:01:09 EST 2016

In a Flask web app I'm building, I have a number of pages. Each page has
essentially the same HTTP response headers, such as:
    r = make_response(render_template('response.html' **templateData))
    r.headers.set('Content-Security-Policy', "default-src 'self';
script-src 'nonce-" + str(scriptNonce) + "' 'self'")
    r.headers.set('X-XSS-Protection', '1; mode=block')
    r.headers.set('X-Content-Type-Options', 'nosniff')
    r.headers.set('X-Frame-Options', 'deny')
    r.headers['Server'] = '' # Can't remove it, so set it to nothing
    return r

Is there a way to templatize this, so it's the same for every page?

John O.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20161117/2259db02/attachment.html>

More information about the Flask mailing list