0

In the following code how to issue 403 for unauthorized?

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")
Rajeev
  • 44,985
  • 76
  • 186
  • 285
  • 1
    possible duplicate of [How do I raise a Response Forbidden in django](http://stackoverflow.com/questions/6618939/how-do-i-raise-a-response-forbidden-in-django) – argaen Jul 15 '15 at 10:06

1 Answers1

0

You are looking for HttpResponseForbidden.

Acts just like HttpResponse but uses a 403 status code.

Ernest
  • 2,799
  • 12
  • 28