简体   繁体   中英

How I get User ID if logged in Django?

I need to get User ID inside from my code (not in Django template).

I've success in template, but not inside the App.

Someone can help me?

here is how you can get a logged in user id in your view:

def user_id(request):
    user = request.user
    print user.id

您可以通过以下方式获取当前登录的用户ID

request.user.id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM