I must admit I was a little surprised that django doesn’t have something akin to phpinfo stashed somewhere in the framework. I needed something that would dump some environment settings to debug some installation issues. What I did find was pyinfo which returns something similar:

Pyinfo screenshot

However, there was one snag and that is that it prints to stdout. Hmpf. How was I going to get django to return this info to the browser? Well, as it turns out, you can hijack the stdout and redirect it to (pretty much) whatever you want. I came across Stefaan Lippens blog entry where he shows exactly how to do this and saved me a bit of work porting pyinfo to work with django. I added this code to the top of pyinfo:

import sys

# a simple class with a write method
class WritableObject:
    def __init__(self):
        self.content = []
    def write(self, string):
    def fullText(self): 
        return ''.join(self.content)
# example with redirection of sys.stdout
foo = WritableObject()                   # a writable object
sys.stdout = foo                         # redirection

and this to the bottom of pyinfo:

sys.stdout = sys.__stdout__

I created an app in my django project called info and then added the following to the urls.py:

(r'^info$', 'myproj.info.views.info'),

I then put my version of pyinfo into the same directory as the views.py file and updated views.py file with the following:

from django.http import HttpResponse
import pyinfo

def info(request):
    return HttpResponse(pyinfo.foo.fullText())

You can download my version of the file here. It’s licensed under the BSD license.