0

I want to filter using token authentication..

if remove get_queryset, get all TodoList author and working at postman.

but I want to filter user like get_queryset.

todo app in views.py

class TodoList(generics.ListCreateAPIView):
serializer_class = TodoSerializer
permission_classes = ()
#queryset = Todo.objects.all()


def get_queryset(self):
    return Todo.objects.filter(user=self.request.user)

def perform_create(self, serializer):
    serializer.save(user=self.request.user)

and using Httpie, I get json I want!

(myvenv) D:\django\todo_project>http GET http://localhost:8000/todo/ "Authorization: Token 7681fc35d7fb9fdb20dbad65ca8220b3ca12c1e6"
HTTP/1.0 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
[
    {
        "content": "todo!",
        "timestamp": "2018-07-11T10:06:27.710916Z",
        "title": "todo!",
        "updated": "2018-07-11T10:06:27.710916Z",
        "user": "user3"
    }
]

but using postman, error occurs.. Postman get

I think when filting, authentication is not working, so user is AnnoymouseUser

How can I filter request user???

1 Answer 1

1

You missed Token word in Authorization value. It should be:

Authorization: Token <token_value>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.