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

I have a quiz_app (situated in the QuizApp folder) inside my (Django) basic_app.我的(Django)basic_app 中有一个 quiz_app(位于 QuizApp 文件夹中)。 Everything is working fine up to the moment, where the game ends and the quiz_end.html (previously end.html) page is not displaying.到目前为止一切正常,游戏结束并且 quiz_end.html(以前的 end.html)页面没有显示。

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)此链接指向 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 statement - if there are no question left, then the game ends) 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");
};

(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) (您可以在此处查看此文件的完整代码 - 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, 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) 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' %}");
  };

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.问题是,这是我第一次尝试在使用 Django 时将浏览器从.js 文件重定向到.html 文件,我真的不知道该怎么做。

The view and the url pattern of the quiz_end.html file should be fine. quiz_end.html 文件的视图和 url 模式应该没问题。 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.我也不知道,为什么游戏结束后浏览器仍然将我重定向到 /end.html 而不是将我重定向到 /quiz_end.html。

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 并像这样调用它来解决它:

{% url 'quiz_app:quiz_end' %}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 404(未找到)- 无法从 Angular 应用程序中的“index.html”页面加载 Javascript 文件 - Angular 404 (Not Found)- Cannot Load Javascript file from 'index.html' page in Angular Application 不知道如何在ember中构建“故事”应用程序 - Don't know how to structure a “story” application in ember HTML和JavaScript,JavaScript没有输出,我不知道为什么? - HTML and JavaScript, no output from javascript, i don't know why? 如何修复CRUD应用程序中的404(未找到)错误? - How do I fix a 404 (Not Found) error in a CRUD application? 我想在同一个html页面中从一种形式转换为另一种形式,例如问题答案测验页面 - I want to move from one form to another in same html page ,like a question answer quiz page 我不知道如何将数组变量从 jquery 传递到其他 php 页面 - I don't know how to passing array variabel from jquery to other php page 防止用户在参加测验的应用程序中重新加载/刷新页面的方法 - Ways to prevent user from reloading/refreshing page in quiz taking application 如何连接 netmiko 和 django 应用程序 - How to connect netmiko and django application 我不知道如何正确地从 fetch 中获取数据 - I don't know how to get data from fetch correctly 我如何将chart.js图表​​保存在一个JS文件中,并且在一个特定的html页面上不存在来自JS文件的ID时不会出现错误? - How do I keep chart.js charts in one JS file, and not get errors when the ID from the JS file don't exist on one specific html page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM