I'm having trouble with Django in terms of getting data from a Javascript form. Here is my Javascript code...
function save() {
var form = document.createElement("form");
console.log(form);
form.setAttribute('method', 'get');
form.setAttribute('action', '/quiz_score/');
document.body.appendChild(form);
var i = document.createElement("input");
i.setAttribute('name', 'Score');
i.setAttribute('value', ""+score);
form.appendChild(i);
var i = document.createElement("input");
i.setAttribute('name', 'csrfmiddlewaretoken');
i.setAttribute('value', '{{ csrf_token }}');
form.appendChild(i);
form.submit();
}
I know using GET isn't ideal however I couldn't get POST working, it simply wouldn't redirect to the target page.
Here is my Django Class and function...
class QuizScoreView(TemplateView):
template_name = "quiz_score.html"
def quiz_score(self, request):
# Quiz.objects.create(username= ,score= )
print("Score: "+request.body)
I am simply trying to get the score variable so I can use it in python.
Please comment if you need any more details and I will add them to the question below.
quiz_scoremethod for? What is calling it?