title: Serving gzipped content from django
body: <p>I'm trying to serve a gzipped version of a text/html page in Django, but Firefox is telling me there's a content encoding error.</p>
  
  <p>NOTES:</p>
  
  <ul>
  <li>I realize this is not a best practice and I'm most likely going to use mod_gzip.  This is just a learning exercise to understand what's going on.</li>
  <li>I know about the Django gzip middleware-- it has problems with binary files. </li>
  </ul>
  
  <p>Here's my code:</p>
  
  <pre><code>rendered_page =  zlib.compress(template.render(context).encode('utf-8'))
  
  response = HttpResponse(rendered_page)
  response['Content-Encoding'] = 'gzip'
  response['Content-Length'] = len(rendered_page)
  return response
  </code></pre>
  
  <p>Am I missing something here?  Is it possible that the content length is wrong?  Are there additional headers I'm missing?</p>
  
  <p>Thanks.</p>