mirror of
https://github.com/django/django.git
synced 2025-12-10 11:25:10 +00:00
Fixed #29082 -- Allowed the test client to encode JSON request data.
This commit is contained in:
parent
d968788b57
commit
47268242b0
7 changed files with 86 additions and 6 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
from urllib.parse import urlencode
|
||||
from xml.dom.minidom import parseString
|
||||
|
||||
|
|
@ -73,7 +74,20 @@ def post_view(request):
|
|||
else:
|
||||
t = Template('Viewing GET page.', name='Empty GET Template')
|
||||
c = Context()
|
||||
return HttpResponse(t.render(c))
|
||||
|
||||
|
||||
def json_view(request):
|
||||
"""
|
||||
A view that expects a request with the header 'application/json' and JSON
|
||||
data with a key named 'value'.
|
||||
"""
|
||||
if request.META.get('CONTENT_TYPE') != 'application/json':
|
||||
return HttpResponse()
|
||||
|
||||
t = Template('Viewing {} page. With data {{ data }}.'.format(request.method))
|
||||
data = json.loads(request.body.decode('utf-8'))
|
||||
c = Context({'data': data['value']})
|
||||
return HttpResponse(t.render(c))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue