title: Django: How to raise Http401 and Http403 exceptions like Http404, RAISE EXCEPTION not RESPONSE
body: <p>I'm trying to make an api using Django, and i'm verifying the request header if it contains an api key and raise an exception according to that, like so:</p>
  
  <pre><code>def _check_driver_authorization(request):
  if request.headers.get('authorization') is not None:
      token = request.headers['authorization']
      user = Driver.objects.filter(access_token=token)
      if user.exists():
          return
  
      raise Http401
  else:
      raise Http403
  </code></pre>
  
  <p>I didn't find anyone trying to make it like this, and i've searched many threads in here, they are all trying to return responses (render), my case i'm trying to interupt the request and raise the exception.
  I inspired this from get_object_or_404.</p>
  
  <p><strong>Edit/update:</strong>
  for more details and explanation, the built-in Http404 exception raises this:
  <a href="https://i.stack.imgur.com/5WdXe.png" rel="nofollow noreferrer">Http404</a></p>
  
  <p>but the exception i tried to make (exactly the same as Http404), raises this:
  <a href="https://i.stack.imgur.com/Ql91G.png" rel="nofollow noreferrer">Http403</a></p>