簡體   English   中英

我不知道如何將 .html 文件之一從測驗應用程序連接到 django 應用程序。 (找不到頁面 (404))

[英]I don't know how to connect one of the .html files from the quiz application to the django application. (Page not found (404))

我的(Django)basic_app 中有一個 quiz_app(位於 QuizApp 文件夾中)。 到目前為止一切正常,游戲結束並且 quiz_end.html(以前的 end.html)頁面沒有顯示。

此鏈接指向 quiz_game.js,它(鏈接)位於 quiz_game.html 文件內 - (在本例中,quiz_js 是位於 django 的 static 文件夾內的文件夾)

<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 語句 - 如果沒有問題,則游戲結束)

if (availableQuestions.length === 0 || questionCounter >= MAX_QUESTIONS) {
    localStorage.setItem("mostRecentScore", score);
    //go to the end page
    return window.location.assign("/end.html");
};

(您可以在此處查看此文件的完整代碼 - https://github.com/jamesqquick/Build-A-Quiz-App-With-HTML-CSS-and-JavaScript/blob/master/Quiz%20App%20Master/ game.js - 它只是稱為 game.js 而不是 quiz_game.js + 您可以在此處查看測驗應用程序中的所有文件 - https://github.com/jamesqquick/Build-A-Quiz-App-With -HTML-CSS-and-JavaScript/tree/master/Quiz%20App%20Master - 唯一的區別是,我必須將 .css 和 .js 文件放到 Django 的 static 文件夾中)

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 ,但它是標准的 url 標記,在添加到 .html 文件時有效,但我不確定,如果將其添加到 .js 文件的正確方法)

getNewQuestion = () => {

  if (availableQuestions.length === 0 || questionCounter >= MAX_QUESTIONS) {
      localStorage.setItem("mostRecentScore", score);
      //go to the end page
      return window.location.assign("{% url 'quiz_end' %}");
  };

問題是,這是我第一次嘗試在使用 Django 時將瀏覽器從.js 文件重定向到.html 文件,我真的不知道該怎么做。

quiz_end.html 文件的視圖和 url 模式應該沒問題。 他們來了 -

def quiz_end(request):
    return render(request,'basic_app/QuizApp/quiz_end.html') 

url(r'^quiz_end/$', views.quiz_end, name='quiz_end'),

我也不知道,為什么游戲結束后瀏覽器仍然將我重定向到 /end.html 而不是將我重定向到 /quiz_end.html。

有人可以幫我嗎? 非常感謝您提前。

我有一個類似的問題,通過將應用程序的命名空間添加到 url 並像這樣調用它來解決它:

{% url 'quiz_app:quiz_end' %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM