How to get an array in Django posted via Ajax

When I try to send an array to Django via Ajax (jQuery)

JavaScript code:

new_data = ['a','b','c','d','e'];
$.get('/pythonPage/', {'data': new_data},function(data){});

and I try to read the array:



I get only the last array value:


What am I doing wrong?


You're looking for the QueryDict's getlist


Quite old question but let me show you full working code for this. (Good for newbie :)

In your template

data = {
    'pk' : [1,3,5,10]

$.post("{% url 'yourUrlName' %}", data, 
        if (response.status == 'ok') {
            // It's all good
        } else {
            // Do something with errors

urlpatterns = [
    url(r'^yourUrlName/', views.yourUrlName, name='yourUrlName'), #Ajax

from django.views.decorators.http import require_POST
from django.http import JsonResponse

def yourUrlName(request):
    array = request.POST.getlist('pk[]')

    return JsonResponse({
            'array': array,

Just use request.GET.getlist('data[]')

Need Your Help

os.mkdir(path) returns OSError when directory does not exist

python system mkdir

I am calling os.mkdir to create a folder with a certain set of generated data. However, even though the path I specify has not been created, the os.mkdir(path) raises an OSError that the path already

Any way to disable Firefox 4 textarea-resizing handles?

firefox resize textarea

I have a site with a textarea that is a very specific size; resizing it could make the user think that they can enter more text into the textarea than is possible (it is limited by rows and columns...