Я отправил ajax запрос на получение в jquery, но render_to_response не работает
Я добавил ниже код
print("request is : ", self.request)
но пусто напечатано
пожалуйста, дайте мне знать, как исправить или отладить
спасибо ~!
блог \ views_cbv.py
class PostDetailView(DetailView):
print("detail view")
model = Post
def render_to_response(self, context):
print("request is : ", self.request)
if self.request.is_ajax():
print("request is ajax ")
return JsonResponse({
'title': self.object.title,
'summary': truncatewords(self.object.content, 100),
})
return super().render_to_response(context)
post_detail = PostDetailView.as_view()
Блог / post_list.html
$(document).ready(function () {
$(document).on('click', '#post_list a', function (e) {
e.preventDefault();
const detail_url = $(this).attr("href");
<!-- alert(detail_url) -->
console.log("detail_url : ", detail_url )
$.get(detail_url)
.done((json_obj) => {
var $modal = $("#post-modal");
console.log("json_obj : ", json_obj)
$modal.find('.modal-title').html(json_obj.title);
$modal.find('.modal-body').html(json_obj.summary);
$modal.find('.btn-detail').attr('href', detail_url)
$modal.modal();
})
.fail((xhr, textStatus, error) => {
alert('failed : ', error);
});
})
});
GitHub:
https://github.com/hyunsokstar/ask_class