Django on Apache web server 'dict' object has no attribute 'render_context'

John Lotacs picture John Lotacs · Jun 13, 2011 · Viewed 8k times · Source

I'm having a bit of a problem, I uploaded my Django project to a webserver running apache, mod_python, and django. On the computer I developed on the following works fine

nameBox = getNamesBox().render(locals())

-

def getNamesBox():
    users = User.objects.filter()

    templateString = '<select name="name box">'
    for user in users:
        templateString += '<option value="' + user.name + '"> ' + user.name + '</option>'

    templateString += '</select>'

    template = Template(templateString)

    return template

But on the web server, when running from apache or manage.py runserver, it says

AttributeError at /order_site/order/
'dict' object has no attribute 'render_context'

The code on both machines is identical so I feel like maybe its some other issue? It can't render my form and I don't know why.

Answer

Rafe Kettler picture Rafe Kettler · Jun 13, 2011

The render() method on a Template takes a Context object as its argument, not a dict. You'll have to construct a Context object from the dict, e.g.

namedbox = getNamesBox().render(Context(locals()))