0👍
✅
After some study I found a solution. There are 2 considerations here:
- Django needs permission and authentication classes
My views.py now looks like this:
class AuthDetailView(BaseDetailView):
authentication_classes = (TokenAuthentication, )
permission_classes = IsAuthenticated,
def get(self, request):
return render(request, 'home.html')
Notice that I don’t have the @login_required
anymore.
- Django likes the authorization header with a ‘Token’ instead a ‘Bearer’ in front of it
When I make a call to my api, auth header should be like Authorization: Token 4571b2dce1f3abec34b28a4c7bd981c248a30698
instead Authorization: Bearer 4571b2d...
After this changes, request.user
is automatically bound to the user previously linked to the token above.
1👍
- Django about get_context_data()
- Django How to access another object by having a user name?
- One url for views with id and not with id
- How to configure wagtail to log admin actions
- How to make Django 'listen' for file uploads to FTP server
Source:stackexchange.com