Ajax成功发布,但Django接收为Null值

时间:2019-05-11 09:18:45

标签: jquery ajax django

Ajax已成功发送数据,但Django函数已将其接收为Null值。...尝试了数天的所有可能方式,但结果仍相同。...请延迟我提交日期。

尝试过尝试以json格式发送,但拒绝了

$.ajax({
          type: "GET",
          url: "results/",
          data: {'datum': 1000},
          success: function(data){
            console.log(data);
            alert("You will now be redirected.");
            window.location.href = "results/";
            },
          error: function(request, status, error, data){
            console.log(error);
        },

  });

Django视图

def thistry(request):
  if request.method == 'GET':

     dat = request.GET.get('datum')
     dee = 9
     return  render(request, 'studentapp/rough2.html', {'dat': dat,     'dee':dee})

django网址

path('weekly/teachers/results/', views.thistry, name='first_page_weekly'),

1 个答案:

答案 0 :(得分:0)

您可以尝试

from django.http import JsonResponse


def thistry(request):
    dat = request.GET.get('datum')
    dee = 9
    return JsonResponse({'dat': dat, 'dee': dee})