1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #24773 -- Added a json() method on test client responses.

This commit is contained in:
Andy McKay
2015-05-08 22:33:26 -07:00
committed by Tim Graham
parent 46ce72e8d2
commit 4525a0c466
6 changed files with 40 additions and 2 deletions

View File

@@ -425,6 +425,20 @@ Specifically, a ``Response`` object has the following attributes:
>>> response.context['name']
'Arthur'
.. method:: json(**kwargs)
.. versionadded:: 1.9
The body of the response, parsed as JSON. Extra keyword arguments are
passed to :func:`json.loads`. For example::
>>> response = client.get('/foo/')
>>> response.json()['name']
'Arthur'
If the ``Content-Type`` header is not ``"application/json"``, then a
:exc:`ValueError` will be raised when trying to parse the response.
.. attribute:: request
The request data that stimulated the response.