[Answered ]-Conditionally authenticate users to DRF view

1👍

What you want is to have no permissions, but still perform authentication.

Authentication validates tokens, gets the user from the database, etc. If you disable it, then no checks of tokens/etc will be performed. This means request.user will always equal AnonymousUser.

class MyView(ListCreateApiView):
    permissions_classes = [AllowAny]
    

It’s worth considering using AllowAny as your permission. It is the same as using a blank list [], but makes it clear your intention is to make the view public, rather than a mistake.

👤Andrew

Leave a comment