Pregunta

I am quite new to Django, especially CBV's. So, I have a listView with a post method, where I am trying to output a JSON as follows:

from django.utils import simplejson

class MyCoolListView(ListView):
   # template declaration and other stuff

    def get_context_data(self, **kwargs):
       # do some stuff
       return context

    def get_queryset(self):
       # do some stuff
       return queryset 

    def post( self, request, *args, **kwargs ):
       # check if user is authenticated and return json
       return HttpResponse( simplejson.dump({ "score": blogpost.score }) , content_type='application/json')

However, the HttpResponse on POST, I get:

TypeError: dump() takes at least 2 arguments (1 given)

I am not entirely sure what I am doing wrong (I have googled this issue quite a bit, but no luck yet) - and I was wondering if anyone had encountered such a situation/error message. Any guidance to solve this would be much appreciated.

¿Fue útil?

Solución

dump is for dumping to a file, you want dumps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top