Facundo Rodriguez
Facundo Rodriguez

Reputation: 37

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

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!

Upvotes: 0

Views: 2243

Answers (2)

caesarsol
caesarsol

Reputation: 2113

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

Upvotes: 1

nnmware
nnmware

Reputation: 950

Try send values in one dictionary

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

Upvotes: 2

Related Questions