Django Type Error - render to string got multiple values for keyword argument context_instance

孤者浪人 提交于 2019-12-11 14:15:48

问题


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!


回答1:


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 ;)




回答2:


Try send values in one dictionary

{'app_label': 'clients', 'results_list':qs}


来源:https://stackoverflow.com/questions/18059342/django-type-error-render-to-string-got-multiple-values-for-keyword-argument-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!