class Response
-
client -
The test client that was used to make the request that resulted in the response.
-
content -
The body of the response, as a bytestring. This is the final page content as rendered by the view, or any error message.
-
context -
The template
Contextinstance that was used to render the template that produced the response content.If the rendered page used multiple templates, then
contextwill be a list ofContextobjects, in the order in which they were rendered.Regardless of the number of templates used during rendering, you can retrieve context values using the
[]operator. For example, the context variablenamecould be retrieved using:>>> response = client.get('/foo/') >>> response.context['name'] 'Arthur'Not using Django templates?
This attribute is only populated when using the
DjangoTemplatesbackend. If you’re using another template engine,context_datamay be a suitable alternative on responses with that attribute.
-
json(**kwargs) -
New in Django 1.9.
The body of the response, parsed as JSON. Extra keyword arguments are passed to
json.loads(). For example:>>> response = client.get('/foo/') >>> response.json()['name'] 'Arthur'If the
Content-Typeheader is not"application/json", then aValueErrorwill be raised when trying to parse the response.
-
request -
The request data that stimulated the response.
-
wsgi_request -
The
WSGIRequestinstance generated by the test handler that generated the response.
-
status_code -
The HTTP status of the response, as an integer. For a full list of defined codes, see the IANA status code registry.
-
templates -
A list of
Templateinstances used to render the final content, in the order they were rendered. For each template in the list, usetemplate.nameto get the template’s file name, if the template was loaded from a file. (The name is a string such as'admin/index.html'.)Not using Django templates?
This attribute is only populated when using the
DjangoTemplatesbackend. If you’re using another template engine,template_namemay be a suitable alternative if you only need the name of the template used for rendering.
-
resolver_match -
An instance of
ResolverMatchfor the response. You can use thefuncattribute, for example, to verify the view that served the response:# my_view here is a function based view self.assertEqual(response.resolver_match.func, my_view) # class-based views need to be compared by name, as the functions # generated by as_view() won't be equal self.assertEqual(response.resolver_match.func.__name__, MyView.as_view().__name__)
If the given URL is not found, accessing this attribute will raise a
Resolver404exception.
You can also use dictionary syntax on the response object to query the value of any settings in the HTTP headers. For example, you could determine the content type of a response using response['Content-Type'].
Please login to continue.