【问题标题】:django response issue 403 for unauthorizeddjango响应问题403未经授权
【发布时间】:2015-10-04 07:30:47
【问题描述】:

在下面的代码中,未经授权如何发出403?

user = authenticate(username=username, password=password)
  if user is not None:
     # the password verified for the user
     if user.is_active:
       print("User is valid, active and authenticated")
       return HttpResponse("Authorized")
     else:
       print("The password is valid, but the account has been disabled!")
       return HttpResponse("Unauthorized")
  else:
      # the authentication system was unable to verify the username and password
      print("The username and password were incorrect.")
      return HttpResponse("Unauthorized")

【问题讨论】:

标签: django


【解决方案1】:

您正在寻找HttpResponseForbidden

HttpResponse 类似,但使用 403 状态码。

【讨论】:

    猜你喜欢
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 2020-02-21
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多