Yckeb
Yckeb

Reputation: 84

Django: render_to_response doesn't work

I have a template perfil.html and want to send this to it:

return render_to_response('perfil.html', query_data,  context_instance=RequestContext(request), {'pseudonimo': usuario.pseudonimo,'seguidores': seguidores(usuario.pseudonimo), 'sigue':sigue(usuario.pseudonimo), 'posts':"En pruebas"})

but it doesn't work. This is the error I have:

Request Method: GET
Request URL:    http://localhost:8000/mi_perfil/
Django Version: 1.8
Exception Type: SyntaxError
Exception Value: non-keyword arg after keyword arg (views.py, line 181)
Exception Location: /home/rebecca/DSI/pretec/pretec/urls.py in <module>, line 3
Python Executable:  /home/rebecca/DSI/env-pretec/bin/python
Python Version: 2.7.3

If I do this:

return render(request,'perfil.html', {'pseudonimo': usuario.pseudonimo,'seguidores': seguidores(usuario.pseudonimo), 'sigue':sigue(usuario.pseudonimo), 'posts':"En pruebas"})

it works, and if I do this:

return render_to_response('perfil.html', query_data, context_instance=RequestContext(request))

it works too but I want to include the two options in the render_to_response

This is my function in the views.py:

def mi_perfil(request):
   usuario = Usuario.objects.get(pseudonimo = request.session['member_id'])
   query = Usuario.objects.all()

   query_data = {
       "user_data" : query
   }
   print query_data
   return render_to_response('perfil.html', query_data, context_instance=RequestContext(request), {'pseudonimo': usuario.pseudonimo,'seguidores': seguidores(usuario.pseudonimo), 'sigue':sigue(usuario.pseudonimo), 'posts':"En pruebas"})

What i am doing wrong? How can I fix it?

Upvotes: 2

Views: 336

Answers (2)

NightShadeQueen
NightShadeQueen

Reputation: 3335

Django's telling you your error quite clearly

Exception Value: non-keyword arg after keyword arg (views.py, line 181)

You have a non-keyword argument (that dictionary) after a keyword arg (context_instance=....)

As to how to fix, uh, could you just...stick that dictionary into your context to start with? You're only allowed one context dictionary (see https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/)

def mi_perfil(request):
     usuario = Usuario.objects.get(pseudonimo = request.session['member_id'])
     query = Usuario.objects.all()

     context = {
          "user_data" : query
          'pseudonimo': usuario.pseudonimo,
          'seguidores': seguidores(usuario.pseudonimo),   
          'sigue':sigue(usuario.pseudonimo),
          'posts':"En pruebas",
                }
     print context
     return render_to_response('perfil.html', context,context_instance=RequestContext(request))

Upvotes: 3

hongshuning
hongshuning

Reputation: 77

Try this:

return render_to_response('perfil.html', query_data,  context_instance=RequestContext(request), dictionary={'pseudonimo': usuario.pseudonimo,'seguidores': seguidores(usuario.pseudonimo), 'sigue':sigue(usuario.pseudonimo), 'posts':"En pruebas"})

Upvotes: -1

Related Questions