Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!