form
, it follows my line of code: / p>
recovery-id.js:
const recoveryButtom = document.querySelector('#recovery-id');
const inputs = document.querySelectorAll('input');
recoveryButtom.onclick = recoveryID;
function recoveryID() {
let csrfToken;
for (let input of inputs) {
if (input.name === 'csrfmiddlewaretoken') {
csrfToken = input.value;
}
}
fetch('/recuperar-id', {
headers:{
'Content-type': 'application/json',
'X-CSRFToken': csrfToken
},
})
.then(function(sucess){
console.log(sucess);
})
.catch(function(error){
console.log(error);
});
}
views.py:
def get_id(request):
form = StudentForm(request.GET or None)
if form.is_valid():
data = form.cleaned_data
student = Student.objects.filter(cpf=data['cpf']).filter(ra=data['ra']).first()
if not student:
return JsonResponse({'studentNotFound': 'O aluno não encontrado'}, status=400)
return render(request, 'index.html', {'student':student})
return JsonResponse({'student':student})
If anyone can help me I will be very grateful, thanks guys!