How to return HTTP 400 response in Django?

I want to return a HTTP 400 response from my django view function if the request GET data is invalid and cannot be parsed.

How do I do this? There does not seem to be a corresponding Exception class like there is for 404:

raise Http404

Solution 1:

From my previous comment :

You can return a HttpResponseBadRequest

Also, you can create an Exception subclass like Http404 to have your own Http400 exception.

Solution 2:

You can do the following:

from django.core.exceptions import SuspiciousOperation
raise SuspiciousOperation("Invalid request; see documentation for correct paramaters")

SuspiciousOperation is mapped to a 400 response around line 207 of https://github.com/django/django/blob/master/django/core/handlers/base.py