Personal tools
You are here: Home Weblog Archive 2009 November 08 Using CherryPy to work around a Django/flup bug
Document Actions
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Using CherryPy to work around a Django/flup bug

by tibi last modified 2009-11-08 22:43
Filed Under:

A bug creeped in one of my Django 1.1 projects that is in beta-testing right now: the Pinax wiki app looks for a REMOTE_ADDR value in request.META, which was not set in my environment. My environment is a pretty standard (as far as this setup goes) nginx + fcgi (flup on the django side) + django. Further work on this issue revealed, step by step, that:

  • REMOTE_ADDR needs to be somehow set by a Django middleware, based on an http header,
  • so I've added django.middleware.http.SetRemoteAddrFromForwardedFor to the list of loaded middleware
  • but that middleware is deprecated in Django 1.1 and does nothing, so I rewrote this middleware based on Chapter 15 of Django Book
  • this new middleware did its job, but for some reason flup stripped that header from the request and the proper values never got to Django
  • this made me look for a replacement for flup, which I found in django-cpserver.

This package adds a new admin command, 'runcpserver', which replaces the default development server by something more appropriate to production. The word on the 'net-streets' is that it runs well and does its job, so I'll be using it for the time being. The recommended solution is to run apache+mod_wsgi and proxy that to nginx, but right now I don't want the extra administrative overhead that Apache represents. If I can't get enough "juice" out of one instance of cpserver, I'll just add an extra instance and balance them with nginx or haproxy.

Weblog
Atom
RDF
RSS 2.0
Powered by Quills
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: