JsonResponse and HTTP Methods
JsonResponse returns JSON. Decorators such as require_http_methods and require_POST limit methods.
Example
from django.http import JsonResponse
from django.views.decorators.http import require_POST
@require_POST
def api_like(request, post_id):
return JsonResponse({"liked": True, "id": post_id})Exercise
Return JSON.
return Response({"ok": True})
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.