2

I use Django Channels to retrieve the data from Django Restful (DRF) serializer (I use channels because database is large and if I call for the data directly it results in a server timeout).

What I struggle with (perhaps I don't understand something about how DRF works), is how to get the html representation of Browsable API. So basically what I need to do is to send back as html a response based on BrowsableAPIRenderer when a person connects via WebSocket:

def connect(self, message, **kwargs):
    myobj = MyObj.objects.filter(code=self.obj_code)
    serializer = MyObjSerializer(myobj, many=True)
    self.send(Response(serializer.data))

But that results in an error Response is not JSON serializable.

David Pekker
  • 333
  • 3
  • 12
  • use `self.send(serializer.data)`. `Response()` is an object, where `serializer.data` is the dictionary representation of your data – Aneesh R S Apr 09 '18 at 03:53

0 Answers0