简体   繁体   English

找不到页面(404)错误,我没有写网址

[英]Page not found (404) error happens I did not write the url

I got an error,Page not found (404) Request Method: GET Request URL: http://localhost:8000/app/test.html?prop=value . 我收到一个错误,找不到页面(404)请求方法:GET请求URL: http://localhost:8000/app/test.html?prop=value I wrote index.html like 我写了index.html

<body>
   <form method="post" action="">
    <select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;">
    {% for i in json_data.items.values %}
            <option value="{{forloop.counter}}">{{ i }}</option>
    {% endfor %}
    </select>

    {% for key, values in preprocessed %}
    <select name="type" id=type{{forloop.counter}}>
    {% for counter, value in values %}
        <option value="{{forloop.counter}}">{{ value }}</option>
    {% endfor %}
    </select>
    {% endfor %}
    </form>

  <script type="text/javascript">

        $(document).ready(function () {
            $('#mainDD').on('change', function() {
              var thisType = "type" + $(this).val();
              for(i=1; i<6; i++) {
                  var thisId = "type" + i;
                  if(thisType !== thisId) {
                    $("#"+thisId).hide();
                  }
                  else {
                    $("#"+thisId).show();
                  }
              }

            }).trigger('change');

        });


  </script>

     <form id="postform" action="http://localhost:8000/app/test_view" method="POST">
      {% csrf_token %}
      <input type="submit" value="SEND">
     </form>
     <script type="text/javascript">
        let key = "prop";
        let value = "value";
        var array1 = [];
        var array2 =[];
          document.querySelector("input[type=submit]").onclick = e => {
           const test = window.open(`test.html?${key}=${value}`, "_blank");
          }

     </script>
  </body>

This part const test = window.open('test.html?${key}=${value}', "_blank"); 这部分const test = window.open('test.html?${key}=${value}', "_blank"); causes error because I did not regist url http://localhost:8000/app/test.html?prop=value . 导致错误,因为我没有注册url http://localhost:8000/app/test.html?prop=value I only register http://localhost:8000/app/test_view . 我只注册http://localhost:8000/app/test_view But I wanna send selected i & value's values to test.html,so I wrote this like. 但是我想将选定的i&value的值发送到test.html,所以我这样写。 I wrote in test.html like 我在test.html这样写

<body>

<h2>RESULT</h2>
    <script type="text/javascript">

      onload = () => {
        document.body.appendChild(
          document.createTextNode([...new URLSearchParams(location.search).entries()])
          );
      }

    </script>

</body>

How should I fix this?What should I write this? 我该如何解决?我该怎么写?

urls.py is urls.py

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^test_view$', views.test_view, name='test_view'),
]

views.py is views.py是

def test_view(request):
    return render(request, 'test.html')

My app structure is testapp(parent app) -app(child app) -inde.html&test.html&views.py 我的应用程序结构是testapp(父应用程序)-app(子应用程序)-inde.html&test.html&views.py

testapp's urls.py is testapp的urls.py

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^app/', include('app.urls')),
]

Now my code is 现在我的代码是

<form id="postform" action="http://localhost:8000/app/test_view" method="GET">
      {% csrf_token %}
      <a href={% url 'test_view' %}>Your link to test view</a>
     </form>
     <script type="text/javascript">
        let key = "prop";
        let value = "value";
        var array1 = [];
        var array2 =[];
          document.querySelector("input[type=submit]").onclick = e => {
           const test = window.open(`test.html?${key}=${value}`, "_blank");
          }

     </script>

You registred http://localhost:8000/app/test_html but try to go by http://localhost:8000/app/test.html link. 您注册了http://localhost:8000/app/test_html但尝试通过http://localhost:8000/app/test.html链接进入。 Your GET parameters don't make a sense. 您的GET参数没有任何意义。

You should use url, that you registred in urls.py . 您应该使用在urls.py url。
Read this tutorial about views and urls. 阅读有关视图和URL的本教程

Change action attribute in your form. 更改表单中的action属性。 It might looks like that: 可能看起来像这样:

In your template your link may looks like this: 在您的模板中,您的链接可能如下所示:

<form id="postform" action="{% url 'test_view' %}" method="GET">

or: 要么:

<form id="postform" action="app/test_view" method="GET">

Instead of: 代替:

<form id="postform" action="http://localhost:8000/app/test_view" method="POST">

This is because in action or another place where you add your url, when you develop in local machine you should write url path without domain: 这是因为在action或添加URL的其他地方,当您在本地计算机上进行开发时,应编写没有域的URL路径:
app/test_view instead of http://localhost:8000/app/test_view app/test_view而不是http://localhost:8000/app/test_view

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

相关问题 我使用 jquery 更改(重写)URL,但是当用户或我刷新页面时,我们收到 404 not found 错误 - I change (rewrite) URL with jquery but when user or I refresh the page, we get 404 not found error 在wordpress中找不到错误404页面 - Error 404 page not found in wordpress 在Django上找不到页面(404)错误 - Page not found (404) error on django 第二次提交后,每当尝试获取登录页面或注册页面时,我都会收到404错误 - I get a 404 error whenever i try to get login page or signup page, after I did my second commit bootstrapValidator ajax提交错误“ 404页面未找到” - bootstrapValidator ajax submit error “404 Page Not Found” 刷新页面时出现 404 NOT found ngnix 错误 - 404 NOT found ngnix error when refrehsing page Keystone错误404“在该地址(404)找不到页面” - Keystone Error 404 “No Page could by found at this address (404)” 我在Facebook上共享链接时遇到404页面未找到错误 - I am getting 404 page not found error when share link on facebook 重新加载页面或手动输入URL(例如“ localhost / mysite.com / contact”)会在Angular js服务器上给出错误的“未找到”(404错误) - Reloading the page or manually type URL like “localhost/mysite.com/contact” gives wrong “Not Found”(404 error) on the server in angular js 在 Ajax 中找不到页面 (404) - Page not found (404) in Ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM