Answer the question
In order to leave comments, you need to log in
Why is request.user equal to AnonymousUser?
I implemented payment on the site using one payment system, which, if the payment is successful, redirects to the page using the POST method. I tried to change something in the db for a specific user, but nothing comes out
@csrf_exempt
def aaa(request):
if request.method == 'POST':
user = request.user
user.username = request.POST['username']
user.save()
return render(request, 'main/aaa.html')
Answer the question
In order to leave comments, you need to log in
If you look in your settings.MIDDLEWARE ,
you will see, for example , django.contrib.sessions.middleware.SessionMiddleware
which takes a session cookie from cookies and adds session data to the request:
session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME)
request.session = self.SessionStore(session_key)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question