Django在Apache web服务器上的'dict'对象没有属性'render_context' [英] Django on Apache web server 'dict' object has no attribute 'render_context'
问题描述
我遇到了一些问题,我将我的Django项目上传到运行apache,mod_python和django的网络服务器。在我开发的计算机上,以下工作正常
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)
返回模板
但是在Web服务器上,从apache或manage.py runserver运行时,它说
AttributeError at / order_site / order /
'dict'object has no attribute'render_context'
这两台机器上的代码是相同的,所以我觉得可能是其他一些问题?它不能渲染我的表单,我不知道为什么。
render()在模板
上使用方法将上下文
对象作为它的参数,而不是字典。你必须从字典中构造一个 Context
对象,例如
namedbox = getNamesBox()。render(Context(locals()))
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.
解决方案 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()))
这篇关于Django在Apache web服务器上的'dict'对象没有属性'render_context'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!