Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Middleware is the preferred way to do things like this on an "every request" basis. For instance, here is a simple bit of middleware to add the same (example) P3P header to every response Django generates:</p> <p>In settings.py:</p> <pre><code>P3P_COMPACT = 'policyref="http://www.example.com/p3p.xml", CP="NON DSP COR CURa TIA"' MIDDLEWARE_CLASSES += ('myapp.middleware.P3PHeaderMiddleware',) </code></pre> <p>In myapp/middleware.py:</p> <pre><code>from django.conf import settings class P3PHeaderMiddleware(object): def process_response(self, request, response): response['P3P'] = getattr(settings, 'P3P_COMPACT', None) return response </code></pre> <p>You could also get a similar effect in a single view by setting the P3P header in the response:</p> <pre><code>def my_view(request): response = render_to_response('my_template.html') response['P3P'] = 'CP="NON DSP COR CURa TIA"' return response </code></pre> <p>To expand on the topic a little bit, cookies and headers such as the P3P header are both sent at the same time, as part of the response; in fact, under the hood, cookies are set with another response header. You can see the cookie header using curl:</p> <pre><code>$ curl --head http://www.google.com/ HTTP/1.1 200 OK Date: Wed, 13 Jan 2010 00:04:59 GMT Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 Set-Cookie: PREF=ID=d2c09762c479f94e:TM=1263341099:LM=1263341099:S=oJby3NpU4RsRfuYa; expires=Fri, 13-Jan-2012 00:04:59 GMT; path=/; domain=.google.com Set-Cookie: NID=30=kdKrd5e-u6Xs7cUe3p4eaNDtv6SO88uBL5v6_M1XMTSRmkh7okxrWLOm-l_uZdN37PxQIe4dBlekFFVCpTFXGyIDlUrz1hEwhgVLvXfIik_VeVWGmWzKbA5qu_Zq0sOi; expires=Thu, 15-Jul-2010 00:04:59 GMT; path=/; domain=.google.com; HttpOnly Server: gws X-XSS-Protection: 0 Transfer-Encoding: chunked </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload