本文介绍了在Django中将多个对象传递给RequestContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将字典和对象传递给模板.所以,我这样做

I need to pass a dict and an object to a template. So, I do this

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

推荐答案

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

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

3rd parameter is processors that should be tuple or list

这篇关于在Django中将多个对象传递给RequestContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 12:51