1. 程式人生 > >assert renderer, '.accept renderer not set on Response'

assert renderer, '.accept renderer not set on Response'

在這裡插入圖片描述
檢視響應了方法寫錯了,不支h持Response,
請使用HttpResponse
JsonResponse

HttpResponse的子類

HttpResponseRedirect 301
HttpResponsePermanentRedirect 302
HttpResponseNotModified 304
HttpResponseBadRequest 400
HttpResponseNotFound 404
HttpResponseForbidden 403
HttpResponseNotAllowed 405
HttpResponseGone 410
HttpResponseServerError 500

redirect

redirect重定向
建議redirect(重定向)和我們前面學習的reverse搭配使用.

from django.http import HttpResponse
def demo_view(request):
return HttpResponse('python', status=400)
或者
response = HttpResponse('python')
response.status_code = 400
response['python'] = '111'
return response