Form Request.GET only get 1 value from multiple selected field

Question:

I have a multi select field using select2 in my form, I want to get all the value selected when submit, but when I print the value, it only gets the value of the last selected option, how can I fix this?

<select class="js-example-basic-multiple" name="Project" multiple="multiple" style="display:inline-block;">
    <option value="ALL" checked="1">ALL</option>
    <option value="1">a</option>
    <option value="2">b</option>
    <option value="3">c</option>
    <option value="4">d</option>
</select>

<script>
    $('.js-example-basic-multiple').select2();
    $('.js-example-basic-multiple').on('change', function() {
    var a = $('.js-example-basic-multiple').val();
})
</script>

view.py

if 'Project' in request.GET:
    print(request.GET['Project'])
Asked By: M.Izzat

||

Answers:

I just changed request.GET['Project'] to request.GET.getlist('Project')

Answered By: M.Izzat
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.