Python Forum

Full Version: Passing Request objects to a serializer in DRF
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.