Q: Pass checked items to python using JSON I am trying to pass checked items to my python code in JSON using an ajax request. The checkboxes are defined in the forms.py file as:
NOTES_OPTIONS = (
    ('0', 'Please add 15% VAT'),
    ('1', 'Price is valid for 45 days'),
    ('2', 'All price is in Ethiopian Birr'),
    ('3', 'Delivery will be within 45 days after PO, advance and bank foreign currency approval'),
    ('4', 'Payment Term 50% advance and remaining amount after delivery'),
    ('5', 'Installation is NOT part of this Quote'),
    ('6', 'If there is discrepancy in price calculation the unit price will prevail')
)
note_choices = forms.MultipleChoiceField(required = False, widget = forms.CheckboxSelectMultiple(attrs={'class': 'form-check-input'}), choices = NOTES_OPTIONS)

and in my create_proposal.html file I have rendered this form as:
<div class="row col-sm-12">
    <div class="col-sm-9" style="margin-left: 10vw;">
        <div class="container"style="margin-bottom: 20vw;">
            <label><Strong>Choose notes to be included:</Strong></label>
                <ul>
                    {{form.note_choices}}
                </ul>
        </div><br><br>
    </div>
</div>

I have a script in which I accept the values from the form inputs and pass them to my merge.py file:
generalData = {
            'file_name': document.getElementById('id_file_name').value,
            'organization_name': document.getElementById('id_organization_name').value,
            'project_type': document.getElementById('id_project_type').value,
            'reference_number': document.getElementById('id_reference_number').value,
            'our_reference_number': document.getElementById('id_our_reference_number').value,
            'date': document.getElementById('id_date').value,
            'exchange_rate': document.getElementById('id_exchange_rate').value,
            'notes': document.getElementById('id_notes').value, 
            'vat': document.getElementById('id_note_choices').value,               
        }
$.ajax({
            url: '/ajax/result/',
            data : { 'values': JSON.stringify(dataJson),
                     'general': JSON.stringify(generalData)
        },
            method: 'GET',
            contentType: "application/json",
            dataType: 'json',
            success: function (data){
                Download(document.getElementById('id_file_name').value);
                alert(data);

            },
            error: function(data) { 
                alert("something went wrong");

            }
        });

the url '/ajax/result/' redirects to the resultPage.
And in my views.py:
def resultPage(request):

    jsonData = request.GET.get('values')
    generalData = request.GET.get('general')
    jsonData = json.loads(jsonData)
    generalData = json.loads(generalData)

    merge(jsonData, generalData)
    return JsonResponse("Document written successfully", safe=False)

As you see in the script I am trying to pass the checkboxes in the JSON as vat and in my merge.py file I tried to  print it's value as:
    print(generalData['vat'])

but this gives me the following error:
    print(generalData['vat'])
KeyError: 'vat'

but when I print(generalData) it gives me:
{'file_name': '', 'organization_name': '', 'project_type': '', 'reference_number': '', 'our_reference_number': '', 'date': '02/17/2020', 'exchange_rate': '0', 'notes': ''}

I also have tried to pass each individual checkbox as:
'vat': document.getElementById('id_note_choices_0').value,

But this also returns 0 whether it is checked or not.
I want to pass different values when each checkbox is clicked. Any solution is appreciated.
Thank you in advance
