2017-10-16 5 views
0

Die URLs einer Seite funktionieren nicht richtig. Ich habe den HTML-Header des Headers (header.html) erstellt. ich es schriebDie URLs einer Seite funktionieren nicht richtig

{% load static%} 
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> 
<link rel="stylesheet" href="{% static 'header.css' %}"> 
<header class="clearfix"> 
     <h1 class="title">WEB SITE</h1> 
     <ul class="top-menu"> 
      <li class="top-menu-item"><a class="icon_head" href="send">SEND</a></li> 
      <li class="top-menu-item"><a class="icon_head" href="see">SEE</a></li> 
      <li class="top-menu-item"><a class="icon_head" href="know">KNOW</a></li> 
      </ul> 
     <a class="logout_button" href="logout_view">LOGOUT</a> 
</header> 

In index.html wird header.html wie

lesen
<html lang="ja"> 

<head> 
    <meta charset="UTF-8"> 
    <link href="/static/css/bootstrap.min.css" rel="stylesheet"> 
    <link rel="stylesheet" href="/static/accounts/detail.css"> 
    <link rel="stylesheet" href="/static/bootflat/css/bootflat.min.css"> 
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script> 

    <title>WEB SITE</title> 
</head> 

<body class="relative"> 

<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> 
<link rel="stylesheet" href="/static/accounts/header.css"> 
{% load static%} 
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> 
    <link rel="stylesheet" href="{% static 'header.css' %}"> 
    <header class="clearfix"> 
      <h1 class="title">WEB SITE</h1> 
         <ul class="top-menu"> 
       <li class="top-menu-item"><a class="icon_head" href="send">SEND</a></li> 
       <li class="top-menu-item"><a class="icon_head" href="see">SEE</a></li> 
       <li class="top-menu-item"><a class="icon_head" href="know">KNOW</a></li> 
       </ul> 
      <a class="logout_button" href="logout_view">LOGOUT</a> 
    </header> 

    <main> 
     <div class="container"> 
      <p>Hello World</p> 
     </div> 
    </main> 

    <footer> 
     <div class="footers"> 
     <ul class="bottom-menu"> 
       <li class="bottom-menu-item"><a class="bottom_index" href="">XOXO</a></li> 
     </ul> 
     </div> 
    </footer> 
</body> 

</html> 

Wenn ich die put header & SEE & Links wissen, sie richtig funktioniert. Auf der anderen Seite schrieb ich in detail.html wie

<html lang="ja"> 
<head> 
    <meta charset="UTF-8"> 
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootflat/2.0.4/css/bootflat.min.css"> 
    <link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> 
    <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootflat/2.0.4/js/jquery.fs.selecter.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootflat/2.0.4/js/jquery.fs.stepper.min.js"></script> 
<title>WEB SITE</title> 
<body class="relative"> 
<header class="clearfix"> 
    <h1 class="title">WEB SITE</h1> 
    <ul class="top-menu"> 
     <li class="top-menu-item"><i class="fa fa-plus" aria-hidden="true"><a class="icon_head" href="send">SEND</a></i> 
     </li> 
     <li class="top-menu-item"><i class="fa fa-eye" aria-hidden="true"><a class="icon_head" href="see">SEE</a></i> 
     </li> 
     <li class="top-menu-item"><i class="fa fa-search" aria-hidden="true"><a class="icon_head" 
                       href="know">KNOW</a></i></li> 
    </ul> 
    <a class="logout_button" href="logout_view">LOGOUT</a> 
</header> 

<main> 
    <div class="container"> 
     <div class="detailimg col-xs-8"> 
      <div class="relative_ele"> 
       <div class="image"> 
        <img class="absolute-fill" src="https://placehold.jp/3d4070/ffffff/150x150.png?text=results.jpg" 
         width="500px" height="300px" alt="SEE"> 
       </div> 
       <div class="vertical-center-container "> 
        <p class="hthree">I LOVE YOU</p> 
        <p class="hthree_small">I MISS YOU</p> 
       </div> 
      </div> 
      <div class="table-padding"> 
       <table border="0 " class="table table-bordered "> 
        <thead> 
        <tr> 
         <th class="index " colspan="4 " bgcolor=pink>ITEMS</th> 
        </tr> 
        </thead> 
        <tbody> 
        <tr> 
         <td bgcolor="#FFEEFF " rowspan="2" align="center ">XOXO1</td> 
         <td align="center "> 
          <a class="index" href="results1">XOXO2</a> 
         </td> 

         <td bgcolor="#FFEEFF " rowspan="4" align="center ">XOXO3</td> 
         <td align="center "> 
          <a class="index" href="results2">XOXO4</a> 
         </td> 
        </tr> 

        </tbody> 
       </table> 
      </div> 
    </div> 
</main> 
<footer> 
     <div class="footers"> 
     <ul class="bottom-menu"> 
       <li class="bottom-menu-item"><a class="bottom_index" href="">XOXO</a></li> 
     </ul> 
     </div> 
</footer> 

</body> 

</html> 

aber wenn ich die SEND-Header setzen & SEE & Links KNOW, sie happens.For Beispiel Sende den Link in index.html nicht funktioniert hat und Fehler, es sendet http://localhost:8000/accounts/send und es ist in Ordnung. SEND link in detail.html sendet jedoch http://localhost:8000/accounts/detail/send. http://localhost:8000/accounts/detai l gilt für URL von Detail.html. Ich kann wirklich nicht verstehen, warum das passiert.Kann ich nicht header.html zu beiden index.html & detail.html verwenden? Wie soll ich das beheben?

Antwort

0

In <a href="send">Send</a> das href Attribut „Senden“ ist ein relativ url: der Browser es löst, indem es auf die aktuelle Seite URL angehängt wird.

Dies ist normalerweise nicht das Verhalten, das Sie möchten. Die Lösung besteht darin, einen absoluten Pfad vom Stamm der Site bereitzustellen. Also, wenn die Lage der Seite „Senden“ wird http://localhost:8000/accounts/send dann die URL einer führendes /, wie dieses Konstrukt:

<a href="/send">Send</a>

und der Browser die URL korrekt immer lösen.

Siehe auch die Antworten auf this question.