B
B
bubaley2020-04-17 00:00:44
Django
bubaley, 2020-04-17 00:00:44

How to properly use json rpc in django?

Hello
I decided to get acquainted with django, I know only very superficial things.
In search of the ideal, I decided to develop an api using json-rpc. The django-modern-rpc library .
According to the documentation, I checked a couple of examples, everything is fine.
But as soon as I decided to make a selection from the database and return it, I got an error

{
  "id": 1,
  "jsonrpc": "2.0",
  "error": {
    "code": -32603,
    "message": "Internal error: Unable to serialize result as valid JSON: Object of type QuerySet is not JSON serializable"
  }
}


The question is how to correctly return selections, objects, etc. ?
(I saw examples where numpy is used, but I'm not sure what the best solution is)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
szelga, 2020-04-17
@bubaley

it is more convenient for your task to use Django Rest Framework. there, in particular, there is such a thing as serializers (which make simple Python data structures from dzhang models and QuerySets; this step, apparently, you have not completed), and typical things are implemented out of the box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question