Request class extends Django’s standard HttpRequest, adding support for flexible request parsing and authentication. It provides a richer API for handling REST-based web services.
Class Signature
The original Django HttpRequest instance
List of parser instances to use for parsing request content
List of authenticator instances to authenticate the request’s user
Content negotiation class instance. Defaults to
DEFAULT_CONTENT_NEGOTIATION_CLASSDictionary of context information passed to parsers
Request Parsing
The Request class provides flexible parsing that allows you to treat requests with JSON data or other media types the same way you handle form data..data
request.POST and request.FILES but with several advantages:
- Includes all parsed content (file and non-file inputs)
- Supports parsing HTTP methods other than POST (PUT, PATCH, etc.)
- Supports flexible request parsing beyond just form data
The parsed request data. Type depends on the content type and parser used.
.query_params
request.GET. Returns the query parameters from the URL.
Dictionary-like object containing all query parameters. Identical to
request.GET.Using
request.query_params makes your code more obvious - any HTTP method can include query parameters, not just GET requests..parsers
APIView or @api_view based on parser_classes or DEFAULT_PARSER_CLASSES setting.
.stream
Stream object for reading request content, or None if content length is 0
Authentication
REST framework provides flexible, per-request authentication with support for multiple authentication policies..user
Typically returns a
django.contrib.auth.models.User instance. For unauthenticated requests, returns AnonymousUser (or None if UNAUTHENTICATED_USER is set to None)..auth
May be a token instance, JWT payload, or other authentication context. Returns
None for unauthenticated requests..authenticators
APIView or @api_view.
.successful_authenticator
None if unauthenticated.
The authenticator instance that authenticated this request
Content Negotiation
The request exposes properties that show the results of the content negotiation stage..accepted_renderer
APIView.
.accepted_media_type
Browser Enhancements
.method
HTTP method name (GET, POST, PUT, PATCH, DELETE, etc.)
.content_type
Media type string (e.g., “application/json”, “multipart/form-data”)
Standard HttpRequest Attributes
SinceRequest extends Django’s HttpRequest, all standard attributes are available:
request.META- Request metadata dictionaryrequest.session- Session dictionaryrequest.POST- Form data (uses DRF parsing)request.FILES- Uploaded filesrequest.COOKIES- Cookie dictionaryrequest.path- Request pathrequest.get_full_path()- Full path including query string
Example Usage
See Also
- Parsers - Content parsing classes
- Authentication - Authentication schemes
- Response - Response class
