WSGIRequest object has no attribute PUT
Я отправляю PUT запрос, но я не понимаю как получить данные из PUT запроса с помощью request
views.py
elif self.request.method == 'PUT':
comment = self.request.PUT['index']
index = self.request.PUT['comment']
review.objects.get(pk=index).update(comment=comment)
return HttpResponse()
toy_detail.html
<script>
$(document).ready(function(){
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
$('.edit').click(function(){
$('.edit').css({'display': 'none'})
index = $(this).data('index');
text = $(this).prev().text();
block = $(this).parent();
block.html(`<h3 class="edit__title">{{request.user.username}}</h3><textarea class="edit__input">${text}</textarea> <button data-index="${index}" class="edit__btn">Edit</button>`)
}
);
$(document).on('click', '.edit__btn', function (){
$('.edit').css({'display': 'block'});
button = $('.edit__btn');
comment = button.prev().val();
index = button.data('index');
parent = button.parent()
$.ajax({
url: 'ajax-update-comment/{{name}}',
method: 'PUT',
headers: { "X-CSRFToken": getCookie("csrftoken")},
data: {
comment: comment,
index: index
},
success: function(response){
parent.html('<div class="comment__item"><h4 class="comment__title">{{request.user.username}}</h4><div class="comment__text">'+comment+'</div></div>');
}
})
})
</script>