title: Django: check cookie on every page?
body: <p>In Django: what's the best way to check whether a cookie is set before loading every page?</p>
  
  <p>Background: I'm working with a site that uses LDAP auth. I want to avoid having to ask for<code>request.META.get('REMOTE_USER')</code> on every single page, because it absolutely hammers the server: it's requested for every resource on the page, the server gets tied up, falls back to Basic auth and the user sees lots of dialogs.</p>
  
  <p>Therefore, I would like to do the following on every page in the site:</p>
  
  <ul>
  <li>check if a user cookie is set</li>
  <li>if not, redirect to a page that consists of just one HTML file, that asks for <code>REMOTE_USER</code> and saves it in a session-length cookie, then redirect back again.</li>
  </ul>
  
  <p>Basically, I want an approximation of the @login_required decorator, without actually using the Django login/user framework.</p>
  
  <p>Any suggestions for the nicest way to do this for all pages in the site, without repeating lots of code?</p>
  
  <p>many thanks!</p>