Python Forum
How to Extend a serializer in Django Rest-Framework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Extend a serializer in Django Rest-Framework
#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,425 Nov-01-2022, 10:51 PM
Last Post: wolfman5874
  Passing Request objects to a serializer in DRF Dexty 0 1,534 Aug-15-2022, 04:51 AM
Last Post: Dexty
  Integrating vue.js with Django framework saisankalpj 0 1,186 Jun-29-2022, 01:32 PM
Last Post: saisankalpj
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,322 Jun-30-2019, 12:21 AM
Last Post: scidam
  Django Rest Framework URL issue marcus 0 2,510 Feb-07-2018, 10:31 PM
Last Post: marcus
  django rest framework - custom routes SparrowhawkMMU 2 6,228 Jan-11-2018, 05:34 PM
Last Post: mariovalentino69
  Django REST - input of some form fields is send twice to the backend ann 4 4,015 Jan-03-2018, 05:43 PM
Last Post: ann
  running Django app with REST chemseddineZ 2 3,298 Apr-07-2017, 03:18 PM
Last Post: shahpy

Forum Jump:

User Panel Messages

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