class JSONResponse HttpResponse def __init__ self data kwargs content

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class JSONResponse(HttpResponse):
def __init__(self, data, **kwargs):
content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json'
super(JSONResponse, self).__init__(content, **kwargs)
def talk_list(request):
if request.method == 'GET':
return JSONResponse(data)
elif request.method == 'POST':
return JSONResponse(error or success)
def talk_detail(request, pk):
try:
talk = Talk.objects.get(pk=pk)
except Talk.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
return JSONResponse()
elif request.method == 'PUT':
return JSONResponse()
elif request.method == 'DELETE':
return HttpResponse(status=204 or errors)