[英]How I get User ID if logged in Django?
I need to get User ID inside from my code (not in Django template). 我需要从代码中获取用户ID(不在Django模板中)。
I've success in template, but not inside the App. 我在模板上成功,但在App内却没有。
Someone can help me? 有人可以帮我吗?
here is how you can get a logged in user id in your view: 这是您如何在视图中获取登录的用户ID的方法:
def user_id(request):
user = request.user
print user.id
您可以通过以下方式获取当前登录的用户ID
request.user.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.