I have deployed a django app and postgresDB using blueprint. It starts and works. The problem is when app must fetch information using this function, it returns error code status 500. In local environment it works perfect. Where is my mistake, please help me!
function getFoodVarieties(foodName) {
const csrftoken = document.querySelector(‘[name=csrfmiddlewaretoken]’).value;
fetch('/api/get_food_varieties\/', {
method: 'POST',
body: JSON.stringify({food: foodName, index: document.getElementById('mealVariety').value}),
headers: {'Content-Type': 'application/json', 'X-CSRFToken': csrftoken},
}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}).then(data => {
var dropdown = document.getElementById('mealVariety');
// Clear any existing options
dropdown.innerHTML = '';
// Populate dropdown with food varieties
data.varieties.map(function (variety, index) {
var option = document.createElement('option');
option.text = variety;
option.value = index;
dropdown.add(option);
});
}).catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
}
document.getElementById('mealName').addEventListener('change', function () {
getFoodVarieties(this.value);
});
document.getElementById('id_quantity').addEventListener('change', function () {
searchFood(this.value)
});