Django 1.7.11:render_to_string()得到了一个意外的关键字参数' context'

时间:2017-11-06 15:23:46

标签: python django

有一些相关问题,例如as this one,但答案似乎不起作用。

我的views.py

中有以下内容
def pilab(request):
    return render(request, 'pilab.html',{'foo':'bar'})

运行它并转到它的相应url会返回以下错误:

Traceback:
File "/data_nfs/opensurfaces2/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/data_nfs/opensurfaces2/server/home/views.py" in pilab
  31.     return render(request, 'pilab.html',{'foo':'bar'})
File "/data_nfs/opensurfaces2/venv/local/lib/python2.7/site-packages/django/shortcuts.py" in render
  50.     return HttpResponse(loader.render_to_string(*args, **kwargs),

Exception Type: TypeError at /pilab/
Exception Value: render_to_string() got an unexpected keyword argument 'context'

扼杀,删除上下文字符串几乎会返回相同的错误:

Traceback:
File "/data_nfs/opensurfaces2/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/data_nfs/opensurfaces2/server/home/views.py" in pilab
  31.     return render(request, 'pilab.html')
File "/data_nfs/opensurfaces2/venv/local/lib/python2.7/site-packages/django/shortcuts.py" in render
  50.     return HttpResponse(loader.render_to_string(*args, **kwargs),

Exception Type: TypeError at /pilab/
Exception Value: render_to_string() got an unexpected keyword argument 'context'

如何修复此错误?

0 个答案:

没有答案