Hi there's no issue there. Let me explain some basics In "pure" Django a cookie called "csrftoken" is the responsible to control authentication and sessions. Hence, for all request Django receives this cookie is sent.
When building REST Api's you are not supposed to have any state at server side, therefore no sessions and this is a concept for RESTfull itself. In order to have authentication in Django Rest, you should implement any type of token authentication. After that from all request from client you will attach the token in the header. The backend will receive this token and from it you will have the user. Depending on your architecture, you can rely on cookie and send the csrf_token in your header aswell. Enough with the basics, take a look at JWT (jason web tokens) Also see the documentation at Django Rest Framework page, regarding authentication. Sorry if I can't be more especific and give you snippets, but reading the docs and understanding this concepts are the initial point. My suggestion is that you try to implement and use Django Rest framework jwt Hope helped in anyway. Em sáb, 30 de nov de 2019 16:06, Yery cs <[email protected]> escreveu: > Hello, How are you? > > I am suck with Django Rest framework issue. > > I am trying to use `request.user` in Django Rest Framework middleware. > > It returns AnonymousUser and I failed. > > I have searched and searched but there is no answer. > > I wonder if this is Django Rest framework issue. > > Who faced this issue? And did you solve? > > Thank you. > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/4c08081d-0706-4b70-b252-63f8ca8f7d17%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/4c08081d-0706-4b70-b252-63f8ca8f7d17%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CA%2Ba7aJ3gY58HSZkMbxvjEg137WK0oioymVfiVQTjPj6MRma1Lw%40mail.gmail.com.
