Django类型错误 - 渲染到字符串获取关键字参数context_instance的多个值 [英] Django Type Error - render to string got multiple values for keyword argument context_instance

查看:2081
本文介绍了Django类型错误 - 渲染到字符串获取关键字参数context_instance的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django中是新的,我收集所有的静态和模板从管理网站进行自定义。现在我试图将一个查询器从管理员站点呈现给change_list.html。

view.py

  def person_list(request): 
如果request.method =='GET':
qs = Person.objects.all()
return render(request,'admin / change_list.html',{'app_label':'客户的},{'results_list':qs})
else:
return render(request,'admin / change_list.html')

我收到此类型错误:

  render_to_string()获取了关键字参数'context_instance'的多个值

这是完整的追溯:

 环境:


请求方法:GET
请求URL:http :// localhost:8000 / clients / persons /

Django版本:1.5.1
Python版本:2.7.4
已安装的应用程序:
('django。 contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'djang o.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'equipment',
'workers',
'客户',
'rents',
'bill',
'pays')
安装的中间件:
('django.middleware.common.CommonMiddleware' ,
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')


追溯:
文件/usr/local/lib/python2.7/dist-packages/django/核心/处理程序/ base.py在get_response
115. response = callback(request,* callback_args,** callback_kwargs)
文件/ home / facundo / dev / BLPServicios / blpservicios / clients / views。 pyin persona_list
9. return render(request,'admin / change_list.html',{'app_label':'clients'},{'results_list':qs })
文件/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py在render
中53.返回HttpResponse(loader.render_to_string(* args,* * kwargs)

异常类型:TypeError at / clients / persons /
异常值:render_to_string()获取关键字参数'context_instance'的多个值

你能帮我解决一下吗?谢谢!

解决方案

我想你正在使用管理模块做一些不能...你在做什么我想你最好尽量做到这一点,而不用管理员呢?



经常自定义它比您自己执行代码更痛苦,因为它的复杂性!



特别是, {%result_list cl%} 您在管理tamplate change_list.html(第91行)中看到的标签不是一个可变模板(您正在上下文中传递的模板),而是模板自定义标签!无论你想做什么,这是错误的路径;)


I'm new in django and I collect all the static and templates from the admin site to customize. Now I'm trying to render a queryset to the change_list.html from the admin site.
view.py

def person_list(request):
    if request.method == 'GET':
        qs = Person.objects.all()
        return render(request, 'admin/change_list.html', {'app_label': 'clients'}, {'results_list':qs})
   else:
       return render(request, 'admin/change_list.html')

And I'm getting this type error:

render_to_string() got multiple values for keyword argument 'context_instance'

Here is the full traceback:

Environment:


Request Method: GET
Request URL: http://localhost:8000/clients/persons/

Django Version: 1.5.1
Python Version: 2.7.4
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'equipment',
 'workers',
 'clients',
 'rents',
 'bills',
 'pays')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/facundo/dev/BLPServicios/blpservicios/clients/views.py" in persona_list
  9.         return render(request, 'admin/change_list.html', {'app_label': 'clients'},     {'results_list':qs})
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py" in render
  53.     return HttpResponse(loader.render_to_string(*args, **kwargs),

Exception Type: TypeError at /clients/persons/
Exception Value: render_to_string() got multiple values for keyword argument 'context_instance'

Can you help me solve this? Thanks!

解决方案

i think you are using the admin module to do something it can't... what are you trying to do?

i guess you'd better try to do it without the admin. often customizing it is more painful than implementing the code yourself, because of its complexity!

in particular, the {% result_list cl %} tag you see in the admin tamplate change_list.html (line 91) is not a template varible (that you are trying to pass in the context) but a template custom tag! whatever you want to do, this is the wrong path ;)

这篇关于Django类型错误 - 渲染到字符串获取关键字参数context_instance的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆