1👍
✅
JSONResponse
is probably using standard python json encoder, which doesn’t really encode the object for you, instead it outputs a string representation (repr
) of it, hence the <Category: The New Category>
output.
You might need to use some external serializer class to handle django objects, like:
If not, you should then normalize object into simple python types inside the view (dict, list, string.., the kind that json module has no problem encoding). So instead doing:
'category':r.category
you could do:
'category': {'name': r.category.name}
Also as a sidenote: using exec
is super bad idea. Don’t use it in production!
0👍
You should return json strings for Angular:
import json
def resource_view(request):
# something to do here
return HttpResponse(json.dumps(your_dictionary))
for better usage i recommend djangorestframework.
Off Topic:
$http.get("{% url 'search-requests-show' %}?term="+$scope.term);
you can pass ‘param’ object:
$http.get("{% url 'search-requests-show' %}", {param : {term:$scope.term}});
- [Answer]-Django automatically fill user detail
- [Answer]-Disable clicking on header elements of django-table2
- [Answer]-Django: Can't load cyrillic font in font-face
- [Answer]-Having trouble adding to postgresql within Django site
- [Answer]-Installing django-dash – Download error, could not find suitable distribution for [multiple packages]
Source:stackexchange.com