[Flask] Templatizing HTTP Response Headers

Can Hosgor canhosgor at gmail.com
Thu Nov 17 15:27:17 EST 2016


You can use @app.after_request decorator to make flask call your function
(in which you can modify the response as you like) at the end of every
request.

17 Kas 2016 Per, saat 23:09 tarihinde John Overbaugh <joatgm at gmail.com>
şunu yazdı:

> 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.
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20161117/9444f199/attachment.html>


More information about the Flask mailing list