mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #24773 -- Added a json() method on test client responses.
This commit is contained in:
parent
46ce72e8d2
commit
4525a0c466
6 changed files with 40 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue