将多个对象传递给django中的RequestContext

时间:2012-04-28 06:03:24

标签: django django-views requestcontext

我需要将dict和对象传递给模板。所以,我这样做

rc = RequestContext(request, {'prob':prob}, {'result':result})
return render_to_response('subject/question.html', context_instance=rc)

但是我收到了错误。

Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.  response = callback(request, *callback_args, **callback_kwargs) File "E:\django-sample\proschools\..\proschools\subject\views.py" in eval_c
  72.   rc = RequestContext(request, {'prob':prob}, {'result':result}) File "C:\Python27\lib\site-packages\django\template\context.py" in __init__
  173.  self.update(processor(request))

Exception Type: TypeError at /practice/c/eval/ 
Exception Value: 'str' object is not callable

2 个答案:

答案 0 :(得分:7)

rc = RequestContext(request, {'prob':prob, 'result':result})

第三个参数是processors,应该是元组或列表

答案 1 :(得分:7)

您还可以使用包含RequestContext的{​​{3}},然后正常传递变量。

from django.shortcuts import render

def someview(request):
    return render(request,'subject/response.html',{'prob':prob,'result':result})