P
P
PyCi2022-01-04 17:52:45
Django
PyCi, 2022-01-04 17:52:45

How to rewrite Django AnonymousUser using DRF?

We need to rewrite the anonymous user in Django. I used the django-custom-anonymous
library , everything works. But the problem is that when a class or function with Django rest framework

from rest_framework.views import APIView
class AnonymousUserAPI(APIView):
    def get(self, request):
        print(request.user.__class__)
        return Response(status=200)

then it returns the dzhangovsky class anonymous and not my new class

A if I use the dzhangovsky function, then there is an anonymous user my rewritten.
from django.http import HttpResponse
def test(request):
    print(request.user.__class__)
    print(request.user.profile)
    return HttpResponse(content=request)


By Debug the anonymous user is mine all the time, up to the point in calling the function which is from DRF.

If anyone has experience with this or has any suggestions, any information would be greatly appreciated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nesterov, 2022-01-04
@PyCi

I am not familiar with the library, but in the general case, when the user model is rewritten, you need to specify it in the settings.
In the case of DRF and Anonymous, the idea is so .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question