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

筅森魡賤 提交于 2019-12-08 19:42:28

问题


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.


回答1:


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()))


来源:https://stackoverflow.com/questions/6333367/django-on-apache-web-server-dict-object-has-no-attribute-render-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!