不清楚404得到ajax错误传递整数到django

时间:2016-11-27 01:31:13

标签: python ajax django

完全不清楚404 Ajax错误。

var int_page_number = 2;
  $.ajax({
        type:'GET',
        url: '/loadmore/',
        data: { 'page_number' : int_page_number},
        dataType: 'json',
        success: function (data) {

            alert(data);          


            }
});

在传递数据的地方,我尝试使用撇号而不是page_number。它的404错误可能在frontedn中,但无论如何我附加django urls.py字符串以防万一:

 url(r'^loadmore/(?P<page_number>[0-9]+)/$', views.loadmore),

和views.py函数,这没关系:

@api_view(['GET', ]) 
def loadmore(request,page_number):
    answers_to_questions_objects = Question.objects.filter(whom=request.user.profile).filter(answered=True).order_by('-answered_date')
    paginator = Paginator(answers_to_questions_objects,10)
    current_page = (paginator.page_number)
    answers = serializers.serialize('json', current_page)
    data = {
        'answers': answers

    }
    return Response(data)`

1 个答案:

答案 0 :(得分:0)

对于您的网址,您应该拨打volatile(), [], @each之类的网址,但是您可以拨打/loadmore/2/这样的电话。所以你的ajax应该是这样的:

/loadmore/?page_number=2