[Django]-How do I use python reverse() function to pass list of ids as query parameter?

1👍

reverse() won’t generate query params. You can just try the string formatting as

path = reverse('admin:app_model_changelist')
result = '%s?id__in=%s' % (path, ','.join(map(str,list_of_ids))) 
👤JPG

1👍

Using kwargs you will have to provide a dictionary with the named arguments, as specified in your URL configuration.

Try instead to use args, like described in the django documentation on resolve():

If the URL accepts arguments, you may pass them in args. For example:

from django.urls import reverse

def myview(request):
   return HttpResponseRedirect(reverse('arch-summary', args=[1945]))

Leave a comment