I'm currently learning in Django, and in this fetch request, I always get the same error. How could I avoid it?
topup.html
let data = new FormData();
data.append('amount', document.getElementById('amount').value);
data.append('csrfmiddlewaretoken', "{{ csrf_token }}");
var response = fetch('{% url "secret" %}', {
method: 'POST',
body: data,
credentials: 'same-origin',
})
views.py
def secret(request):
amount = request.POST["amount"]
error:
MultiValueDictKeyError at /secret
'amount'
Request Method: GET
Request URL: http://127.0.0.1:8000/secret
Django Version: 3.0.6
Exception Type: MultiValueDictKeyError
Exception Value:
'amount'
Exception Location: C:\Users\eric3\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\datastructures.py in getitem, line 78
Python Executable: C:\Users\eric3\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version: 3.8.2
I would really appreciate some help.
Thanks!