"You cannot access body after reading from request's data stream"
I have a piece of code that sends a json to the server but
form.onsubmit = async (e) => {
e.preventDefault();
const formData = new FormData(form);
const response = await fetch('api/get-comments/', {
method: 'POST',
body: formData
});
if (response.ok) {
await fetchComments();
document.getElementById('commentText').value = '';
}
}
when I try to read it it comes back with an error that it can't access the body
def get_comments(request, gameID: int):
"""Renders the comment page."""
assert isinstance(request, HttpRequest)
if request.method == "POST":
comment_text = json.get(request.body)
user = request.user
# comment = Comments(
# userID=user,
# gameID = Games.objects.get(gameID=gameID),
# commentText=comment_text,
# commentTime=datetime.now()
# ).save()
return HttpResponse(comment_text ,status=201)