I got a question with my Django project. I have a database and want to get data into JavaScript with a fetch request. The data should just be in JSON. This was my attempt with Serializer. Is there a more easy way, than writing a whole serializer.py. Does anybody have an idea what to do.
JavaScript:
fetch('', {
method: 'GET',
})
.then(response => response.json())
.then(data => {
console.log(data);
});
DJango views.py:
def ausgeben(request):
if request.method == 'GET':
ausgeben = Schraube.objects.all()
serializer = SchraubeSerializer(schrauben, many=True)
return JsonResponse(serializer.data, safe=False)
return render(request, 'AR-Ausgeben.html', all_items)