0
Talk guys good day, I’m with a form
that the user enters Cpf and ra and receives its id_registration
, I’m trying to do this with ajax, but always returns 500 Internal Server Error
, follows my line of code:
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);
});
}
py views.:
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!!!
If it returns error 500, it means that there is an error in this function, which the debug of Django shows about?
– Giovanni Nunes