Python Forum
How to Extend a serializer in Django Rest-Framework - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: How to Extend a serializer in Django Rest-Framework (/thread-37928.html)



How to Extend a serializer in Django Rest-Framework - Dexty - Aug-10-2022

I have a stand-alone app and a corresponding api. The idea is to consume the api in a browser extension. I can utilize the objects from a GET request in the app's views like so:
def room(request, room):
    username = request.session.get("user_name")
    if username:
        room_details = Room.objects.get(name=room)
        message = Message.objects.all()

        return render(request, 'room.html', {'room': room, 'message': message})
The challenge now is accessing/serializing request.session.get("user_name") or any other object of request on the client side when I want to fetch the endpoint. I need to be able to do this also to check user authentication in the browser extension (not using DRF's auth for this).

Meanwhile DRF's context seem not to work for this use case.