Skip to content
Advertisement

django ‘str’ object has no attribute ‘_meta’

Sorry for my English. I have some data from another server, but I need to output this data like JSON.

if i print response in console:

JavaScript

but, if i return this response like HttpResponse i have an error

AttributeError: ‘str’ object has no attribute ‘_meta’

this my code:

JavaScript

UPD:

I tried with this:

JavaScript

but have error:

Object of type ‘ModelYears’ is not JSON serializable

UPD:

I did like this:

JavaScript

but have error:

JavaScript

Advertisement

Answer

The Django docs says the following about the serializers framework:

Django’s serialization framework provides a mechanism for “translating” Django models into other formats.

The error indicates that your variable response is a string and not an Django model object. The string seems to be valid JSON so you could use JsonResponse:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement