The context within I was receiving this error was in a view function that was "supposed" to be returning a list of strings in json. If you have any experience with returning Django queryset results in json you probably immediately think of doing something like this:
#Not what you want! from django.core import serializers from django.http import HttpResponse from myproject.myapp.models import MyModel def get_my_strings(request): some_models = MyModel.objects.filter(user=request.user) my_strings = [] for s in my_strings: my_strings.append(some_models.some_string) #error will be thrown my_strings = serializers.serialize('json', my_strings) return HttpResponse(my_strings, mimetype='application/json')
This is wrong.
What you actually want is to use the simplejson.dumps function to serialize your data. Here is the correct form:
What you actually want is to use the simplejson.dumps function to serialize your data. Here is the correct form:
#Import simplejson instead from django.utils import simplejson from django.http import HttpResponse from myproject.myapp.models import MyModel def get_my_strings(request): some_models = MyModel.objects.filter(user=request.user) my_strings = [] for s in my_strings: my_strings.append(some_models.some_string)  #Corrected! my_strings = simplejson.dumps(my_strings, indent=4) return HttpResponse(my_strings, mimetype='application/json'