Fetch call of 'PUT' method in Django produces a 500 status error

When I try to make a fetch "PUT" request, but no matter what it returns 500 status (Internal Server Error) error.
I've been trying to fix this error now for hours, but honestly have no idea what is the actual problem.
Here is my code:
Index.js (only a useful chunk of it)

document.querySelectorAll(".bi").forEach(function (icon) {
    icon.addEventListener("click", (event) => like(event));
  });

  function like(event) {
    const target = event.target;
    const parent = target.parentElement.parentElement;
    const id = parent.className.slice(-1);
    const count = parent.querySelector("#like-count");
    const number = parseInt(count.innerText);
    console.log(`${number+1}`);

    fetch(`/like`, {
      method: "PUT",
      headers: {
        "X-CSRFToken": getCookie("csrftoken"),
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        'id': id,
      }),
    })
      .then(response => console.log(response))
      .then(data => {
        console.log(data);
        /* console.log(data.like);
        if (data.like) {
          target.id = "icon-svg";
          count.innerText = `${number - 1}`;
        } else {
          target.id = "icon-svg-q";
          count.innerText = `${number + 1}`;
        } */
      })
      .catch(error=>console.log(error));
  }

views.py (only a useful chunk of it)
@login_required
def like(request):
    if request.method == 'PUT': 
        js = json.loads(request.body)
        id = int(js['id'])
        post=Post.objects.get(pk=id)
        _user =request.user
        liked=False
        for i in post.likes.all():
            if i.user ==  request.user:
                liked=True
        if not liked:
            try:
                f = Like.objects.get(user=_user, post=post)
                return JsonResponse({
                "result":False,
                "like":liked
            }, status=400)
            except Like.DoesNotExist:
                f = Like(user=_user, post=post)   
                f.save()
                return JsonResponse({
                "result":True,
                "like":liked
            }, status=200)
        else:
            try:
                f = Like.objects.get(user=_user, post=post)
                f.delete()
                return JsonResponse({
                "result":True,
                "like":liked
            }, status=200)
            except Like.DoesNotExist:
                return JsonResponse({
                "result":False,
                "like":liked,
            }, status=400)
    else:
        return  JsonResponse({
            "result":'Complete disaster'
        }, status=400) 

urls.py
from django.urls import path

from . import views

urlpatterns = [
    path("", views.index, name="index"),
    path("<str:page>", views.index, name="index"),
    path('profile/<str:username>', views.profile, name='profile'),
    path('follow/<str:username>', views.follow, name='follow'),
    path('post', views.post, name='post'),
    path('unfollow/<str:username>', views.unfollow, name='unfollow'),
    path("login", views.login_view, name="login"),
    path("logout", views.logout_view, name="logout"),
    path("register", views.register, name="register"),
    path('following', views.following, name="following"),
    path("following/<str:page>", views.following, name="following"),
    path('like', views.like, name='like'),
    path('edit', views.edit, name='edit'),
]<br>

If you need any other information to help you better understand my question feel free to ask!

Back to Top