【问题标题】:How to get the user while Logout In django如何在django中注销时获取用户
【发布时间】:2020-09-01 11:12:40
【问题描述】:

我正在尝试让用户从 django 注销并将其作为参数传递给外部 python 脚本。 这是我的注销视图:

def logoutUser(request):
    user = request.user
    exec = run([sys.executable,'scriptlogout.py', user], shell=False, stdout=PIPE)
    logout(request)
    return redirect('beesy:Login')

但这不起作用,我无法检索点击注销的用户

谢谢你帮助我

【问题讨论】:

  • usernot 一个字符串,它是一个User 对象(严格来说是一个惰性对象),所以你不能在@ 中使用user 987654325@ 部分。
  • 感谢您的回复您对我想做的事情有什么建议吗?
  • 如果你使用exec = run([sys.executable,'scriptlogout.py', user.username], shell=False, stdout=PIPE)会怎样

标签: python django logout


【解决方案1】:

谢谢大家,我用过 str() 并且效果很好:

def logoutUser(request):
    user = str(request.user)
    exec = run([sys.executable,'scriptlogout.py', user], shell=False, stdout=PIPE)
    logout(request)
    return redirect('beesy:Login')

【讨论】:

    猜你喜欢
    • 2014-10-04
    • 1970-01-01
    • 2021-11-23
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    相关资源
    最近更新 更多