Why Autocomplete form in django doesn't work

I have been trying several different kind of code for an autocomplte form with Django Im new on this but here are the code:


def search_ifsc(request):
        q = request.GET.get('q', '').capitalize()
        search_qs = InfoTrabajadores.objects.filter(documento__startswith=q)
        results = []
        for r in search_qs:
            dict_data = {'documento':r.documento,'nombres':r.nombres,'info':{
        data = json.dumps(results)
    except Exception as e:
        data = 'fail'+ f'\n{e}'

    mimetype = 'application/json'
    return HttpResponse(data, mimetype)

This in the endpoint to filter te data with the document Inside the document:

 <script type='text/javascript'>

  .then((response) => response.json())
  .then((data) => {
       document.getElementById('nombre').value = data.nombres;
      document.getElementById('num_emergencia').value = data.num_emergencia;
      document.getElementById('prov_salud').value = data.prov_salud;
      document.getElementById('prov_salud_trabj').value = data.prov_salud_trabj;
      document.getElementById('rh').value = data.rh;
    } )

And the urls.py

urlpatterns = [
    path('ajax/search/' , search_ifsc, name='search_view'),

This is how the site looks with the actual code

I've been trying change de model and how the query works, but nothing change the response in the site

Back to Top