my request.user is anonymous

when I use firefox or edge,after I use user=authenticate(request,username=username,password=password)
and then I reload my front-end page, the request.user is still anonymous,but when I use chrome, it login successfully,what’s wrong?

I don’t really know exactly what happened but you can check these hypotheses:

  • Clear your browsers cache or just navigate with private window.

  • insert the @login_required decorator on the view

  • you can also verifie if the request.user.is_anonymous returns True.


thank you,I insert the @login_required and the front-end page console said ```

   Access to XMLHttpRequest at '' (redirected from '') from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. ``` on edge,and the chrome still login successfully

you obviously using Django Rest Framework ?
So you need to include the CORS management systems in your settings file.
It allow your front to be able to communicate with the back.

1 Like

You need these:

  • python -m pip install django-cors-headers

In your installed app, insert this



In your MIDDLEWARE, insert this



After find somewhere at bottom to insert this


this is the link for further informations Cors

1 Like

thank you so much! but my console error changes to

   Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values ',', but only one is allowed.

Try to put ‘*’ which means “all” in CORS_ALLOWED_ORIGINS = ['*']

Don’t forget the link in my third point

1 Like

Is it related to my nginx? there is a add_header 'Access-Control-Allow-Origin' '*' in my nginx.conf

I don’t think so, try to have access without the NGINX server to see the behavior .

1 Like

I delete the add_header in my nginx.conf and the console error changed to
GET 404 (Not Found)
now when I login