Pass request.user to view without altering the url

后端 未结 3 781
死守一世寂寞
死守一世寂寞 2021-01-22 17:50

I\'m trying to write a view where the current logged in user\'s information is retrieved.

My view is written as below, and it works perfectly fine as long as I pass the

3条回答
  •  抹茶落季
    2021-01-22 18:08

    You don't really have to pass anything via url. You can directly access the logged in user from request.user. You can read about this over here. Also, you can check if the user is logged in using is_authentcated() method or using the login_required decorator

    def ur_view(request):
       #Check if the user is logged in
       if not request.user.is_authenticated():
              #your logic if user not logged in
       else:
            #If the user is logged in
    

提交回复
热议问题