Python Forum
Passing Request objects to a serializer in DRF
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing Request objects to a serializer in DRF
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Initializing a Serializer in init and passing data later wolfman5874 1 1,424 Nov-01-2022, 10:51 PM
Last Post: wolfman5874
  How to Extend a serializer in Django Rest-Framework Dexty 0 1,729 Aug-10-2022, 02:53 PM
Last Post: Dexty
  Is it possible to perform a PUT request by passing a req body instead of an ID ary 0 1,823 Feb-20-2019, 05:55 AM
Last Post: ary

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020