Skip to main content
The 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

from rest_framework.request import Request

Request(
    request,
    parsers=None,
    authenticators=None,
    negotiator=None,
    parser_context=None
)
request
HttpRequest
required
The original Django HttpRequest instance
parsers
list | tuple
default:"()"
List of parser instances to use for parsing request content
authenticators
list | tuple
default:"()"
List of authenticator instances to authenticate the request’s user
negotiator
object
default:"None"
Content negotiation class instance. Defaults to DEFAULT_CONTENT_NEGOTIATION_CLASS
parser_context
dict
default:"None"
Dictionary 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.data
Returns the parsed content of the request body. Similar to 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
data
dict | list | QueryDict
The parsed request data. Type depends on the content type and parser used.
Accessing request.data may raise ParseError if the client sends malformed content, or UnsupportedMediaType if the content type cannot be parsed.

.query_params

request.query_params
A more semantically correct name for request.GET. Returns the query parameters from the URL.
query_params
QueryDict
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

request.parsers
List of parser instances that will be used to parse the request content. Automatically set by APIView or @api_view based on parser_classes or DEFAULT_PARSER_CLASSES setting.

.stream

request.stream
Returns a stream representing the content of the request body. You typically won’t need to access this directly.
stream
file-like object | None
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

request.user
Returns the user associated with the current request, as authenticated by the authentication classes.
user
User | AnonymousUser
Typically returns a django.contrib.auth.models.User instance. For unauthenticated requests, returns AnonymousUser (or None if UNAUTHENTICATED_USER is set to None).
# Example usage
def my_view(request):
    if request.user.is_authenticated:
        return Response({'message': f'Hello, {request.user.username}'})
    return Response({'message': 'Hello, guest'})

.auth

request.auth
Returns additional authentication context. The exact value depends on the authentication policy used.
auth
any | None
May be a token instance, JWT payload, or other authentication context. Returns None for unauthenticated requests.
# Example: Token authentication
if request.auth:
    print(f"Authenticated with token: {request.auth.key}")

.authenticators

request.authenticators
List of authentication instances used to authenticate the request. Automatically set by APIView or @api_view.

.successful_authenticator

request.successful_authenticator
Returns the authentication instance class that successfully authenticated the request, or None if unauthenticated.
successful_authenticator
BaseAuthentication | None
The authenticator instance that authenticated this request

Content Negotiation

The request exposes properties that show the results of the content negotiation stage.

.accepted_renderer

request.accepted_renderer
The renderer instance selected by content negotiation. Set automatically by APIView.

.accepted_media_type

request.accepted_media_type
String representing the media type accepted by content negotiation.

Browser Enhancements

.method

request.method
Returns the uppercased string representation of the request’s HTTP method.
method
str
HTTP method name (GET, POST, PUT, PATCH, DELETE, etc.)
Browser-based PUT, PATCH, and DELETE forms are transparently supported through form overloading.

.content_type

request.content_type
Returns the media type of the HTTP request’s body, or an empty string if none was provided.
content_type
str
Media type string (e.g., “application/json”, “multipart/form-data”)

Standard HttpRequest Attributes

Since Request extends Django’s HttpRequest, all standard attributes are available:
  • request.META - Request metadata dictionary
  • request.session - Session dictionary
  • request.POST - Form data (uses DRF parsing)
  • request.FILES - Uploaded files
  • request.COOKIES - Cookie dictionary
  • request.path - Request path
  • request.get_full_path() - Full path including query string

Example Usage

from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['GET', 'POST'])
def example_view(request):
    # Access parsed data
    if request.method == 'POST':
        data = request.data
        return Response({
            'received': data,
            'user': request.user.username,
            'method': request.method
        })
    
    # Access query parameters
    search = request.query_params.get('search', '')
    return Response({'search': search})

See Also

Build docs developers (and LLMs) love