Autocomplete form in django

i'm trying to make an autocomplete form in django but when i run the page locally don´t run because don't find the url of the json, the idea of the autocomplete is that take information from x table and then the form post the information in y table

views.py

def is_ajax(request):    
  return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'def 

get_employee(request):    
  if is_ajax(request=request):        
  q = request.GET.get('term', '')        
  places = InfoTrabajadores.objects.filter(documento__icontains=q)        
  results = []        
  for pl in places:           
    place_json = {}           
    place_json['label'] = pl.state           
    results.append(place_json)        
   data = json.dumps(results)    
  else:        
   data = 'fail'    
  mimetype = 'application/json'    
  return HttpResponse(data, mimetype)

and the jquery

$(document).ready(function() {
    async function getCities(event, ui) {
        let url = '{% url ' / api / get_employees / ' %}';
        let url = 'http://127.0.0.1:8000/api/get_employees/';
        let results = await fetch(url);
        let data = await results.json();
        return data;
    };
    async function AutoCompleteSelectHandler(event, ui) {
        let zipCode = await getCities();
        $('#nombre').val(nombre[ui.item.value]);
        $('#num_emergencia').val(num_emergencia[ui.item.value]);
        $('#prov_salud').val(prov_salud[ui.item.value]);
        $('#prov_salud_trabj').val(prov_salud_trabj[ui.item.value]);
        $('#rh').val(rh[ui.item.value]);
    };
    $("#autoSuggest").autocomplete({
        source: "{% url 'invitados' %}",
        select: function(event, ui) {
            AutoCompleteSelectHandler(event, ui)
        },
        minLength: 2,
    });
});
Back to Top