Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 300
John Lotacs Avatar asked Jun 13 '11 16:06

John Lotacs


1 Answers

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()))
like image 112
Rafe Kettler Avatar answered Nov 04 '22 18:11

Rafe Kettler