提问者:小点点

如何从Ajax为django获取id文章


我拿着id产品,试着去查看django,总是犯错误,我怎么能在查看数据? 请帮忙

我不明白我从请求中得到了什么数据,我怎么才能查看内部

null

$(function () {
  $(".js-take-id").click(function () {
    alert("вы нажали на кнопку скрипта Poka! с номером товара id="+ $(this).data("id"));
    const csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
$.ajaxSetup({
    beforeSend: function(xhr, settings) {
            xhr.setRequestHeader("X-CSRFToken", csrftoken);
    }
});
    $.ajax({
      url: '/articles/',
      type: 'post',
      dataType: 'json',
      data: {
        'id': $(this).data("id"),
      }
    });
  });
});

null

class MainArticles(ListView):
template_name = 'dishes/articles.html'
model = Articles

def post(self, request):
    name = request.POST.get('/articles/')
    #data = json.loads(request.POST.get('data'))
    data = json.dumps(request.POST.get('/articles/'))
    return HttpResponse('HelloWorld')

共1个答案

匿名用户

        for i in name.keys():
        a[i] = name[i]
    articles = get_object_or_404(Articles, pk=a['id'])
    context = {'articles': articles}

这是工作。