繁体   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