Python Forum
Passing Request objects to a serializer in DRF - 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: Passing Request objects to a serializer in DRF (/thread-37960.html)



Passing Request objects to a serializer in DRF - Dexty - Aug-15-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.