I have a quiz_app (situated in the QuizApp folder) inside my (Django) basic_app. Everything is working fine up to the moment, where the game ends and the quiz_end.html (previously end.html) page is not displaying.
This link is pointing to quiz_game.js and it (the link) is situated inside the quiz_game.html file - (quiz_js is in this case a folder situated inside the django´s static folder)
<script src="{% static "quiz_js/quiz_game.js" %}">
Here is some kind of link to the end.html file (please note, that the end.html will soon be renamed to quiz_end.html file) and the link is situated inside the quiz_game.js file - (it is a part of the if statement - if there are no question left, then the game ends)
if (availableQuestions.length === 0 || questionCounter >= MAX_QUESTIONS) {
localStorage.setItem("mostRecentScore", score);
//go to the end page
return window.location.assign("/end.html");
};
(You can see the full code of this file here - https://github.com/jamesqquick/Build-A-Quiz-App-With-HTML-CSS-and-JavaScript/blob/master/Quiz%20App%20Master/game.js - it´s just called game.js instead of quiz_game.js + You can see all of the files from the Quiz App here - https://github.com/jamesqquick/Build-A-Quiz-App-With-HTML-CSS-and-JavaScript/tree/master/Quiz%20App%20Master - The only difference is, that I have to put the.css and.js files to the Django´s static folder)
I have renamed the end.html file to quiz_end.html and since I am using Django, I was trying to incorporate Django´s template tag into the quiz_game.js file like this - (I am not sure, if I am doing it right, but it is a standart url tag, which works when being added to.html files, but I am not sure, if it is the right way to add it to the.js files)
getNewQuestion = () => {
if (availableQuestions.length === 0 || questionCounter >= MAX_QUESTIONS) {
localStorage.setItem("mostRecentScore", score);
//go to the end page
return window.location.assign("{% url 'quiz_end' %}");
};
The thing is, that this is my first time, when I am trying to redirect the browser from.js file to.html file while using Django and I do not really know, how to do it.
The view and the url pattern of the quiz_end.html file should be fine. Here they are -
def quiz_end(request):
return render(request,'basic_app/QuizApp/quiz_end.html')
and
url(r'^quiz_end/$', views.quiz_end, name='quiz_end'),
I also don´t know, why is the browser still redirecting me to /end.html instead of redirecting me to /quiz_end.html, when the game is finished.
Could anybody help me please? Thank You very much in advance.
I had a similar problem, it was solved by adding app's namespace to urls and calling it like this:
{% url 'quiz_app:quiz_end' %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.