Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Django: set dynamic array in urlpatterns from urls.py

I have this function that I want to use in order to delete some records from a database. It takes as input an array of ints.

function deleteScript(idList){
    $.ajax({
        url: '/delete',
        type: 'get',
        data: {
            ids: idList
        },
        success: function(response) {
            alert('success')
        }
    })
    console.log('ajax sent')
}

How can I set the django dynamic url so that no matter the list, the request would always call the same method (e.g. http://localhost:8000/delete/?ids%5B%5D=1&ids%5B%5D=2 http://localhost:8000/delete/?ids%5B%5D=5 would go to delete/)?

urls.py

urlpatterns = [
    path('', views.get_data),
    path('delete/<list:ids>', views.delete)
]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can pass the id list as comma separated values:

?id=1,4,5

And then parse it in Python to a list.

id_param = request.GET['id']
try:
  ids = [int(a) for a in id_param.split(',')]
except ValueError:
  # handle improper request
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda