Вызов Ajax из шаблона django завершается с ошибкой: Поле 'id' ожидало число, но получило 'populate_sections'

У меня есть один URL в файле urls.py, как указано ниже:-

urlpatterns = [
        ........
      path('edit_student/<student_id>', views.edit_student, name="edit_student"),
      path('populate_sections', views.populate_sections, name="populate_sections"),
      ..........
      ]

В файле views.py функция edit student определена следующим образом:

@login_required
def edit_student(request, student_id):
 form = UpdateStudentForm()
 context = {
           "form": form
}
return render(request, "edit_student.html", context)
< <
    $.ajax({
        url: 'populate_sections',
        type: 'GET',
        data: {class_name:class_name},
        dataType: 'json',
        success: (data) => {
            $("#id_section_name").empty();
            for( var i in data.context){
                $("#id_section_name").append("<option value='"+data.context[i].id+"'>"+data.context[i].name+"</option>");
            }
        }
    });
});

Функция populate_section файла views.py объявлена следующим образом:-

@login_required
def populate_sections(request):
is_ajax = request.headers.get('X-Requested-With') == 'XMLHttpRequest'
if is_ajax:
    if request.method == 'GET':
        class_name = request.GET.get("class_name")
        class_object = Classes.objects.get(id=class_name)
        sections = Sections.objects.filter(classes=class_object)
        return JsonResponse({'context': list(sections.values())})
    return JsonResponse({'status': 'Invalid request'}, status=400)
else:
    return HttpResponseBadRequest('Invalid request')

Когда я изменяю поле, которое запускает вызов функции Ajax, я получаю ошибку значения:

ValueError at /edit_student/populate_sections

Значение исключения:
Поле 'id' ожидало число, но получило 'populate_sections'.

Я понимаю, что он ожидает идентификатор студента, но как это сделать.

<
Вернуться на верх