Django

Code

Setting Up mod_python

This is dealt with more in the installation area here: http://www.djangoproject.com/documentation/modpython/.

Troubleshooting mod_python

MD5 Issues

It has been reported that mod_python has trouble returning good MD5 strings. It has been speculated that this is because many apache mods are using the same md5 source (php and so forth), but this is not confirmed. It is likely working in most versions of mod_python, but some have had troubles with it. A workaround is to use SHA strings instead of MD5. A ticket has been submitted (ticket:2249) that would allow one to specify SHA or MD5 session keys to avoid this problem in the future, but as of now, you have to manually update django to make this work.

How to do the update

  1. Find your django install, it should live inside the site-packages directory of python. On debian this is /usr/lib/python#.#/site-packages. The #'s are your version number. Other OS's may stick python in different places.
  2. You are going to be modifying django/contrib/sessions/models.py and django/contrib/admin/views/decorators.py. Make backups of those two files.
  3. Find the line at the top of the scripts that imports md5. Add sha so that the line looks something like this:
    import base64, md5, sha #there may be a bunch more stuff after this
    
  4. Next, replace all instances of "md5" with "sha" throughout the documents. A search and replace is fine.
    #For example, the following two lines which originally looked like this:
    pickled_md5 = md5.new(pickled + settings.SECRET_KEY).hexdigest()
    return base64.encodestring(pickled + pickled_md5)
    
    #would now look like this:
    pickled_sha = sha.new(pickled + settings.SECRET_KEY).hexdigest()
    return base64.encodestring(pickled + pickled_sha)
    
  5. SHA strings are 40 characters, not 32, we need to fix the string splitting:
    #Find the lines that look like this:
    pickled, tamper_check = encoded_data[:-32], encoded_data[-32:]
    
    #And change them to this:
    pickled, tamper_check = encoded_data[:-40], encoded_data[-40:]
    
  6. Done.

That's all there is to it. Restart apache after saving the files and try to go to your admin area. If you have any additional problems, please head over to the irc channel.