django项目

时间:2016-05-03 06:27:00

标签: javascript html css django python-2.7

我已为所有css文件添加了静态文件链接。仍然只有HTML文件显示在浏览器中。 CSS文件不起作用。如果有什么不对,请告诉我。如何纠正?

我访问了 index.html 页面的页面源代码,然后点击了CSS链接。它不显示CSS文件。它显示了一些其他HTML文件。我收到错误:error page not found

的index.html

<head>{% load static %}
  <link rel="stylesheet" href="{% get_static_prefix as STATIC_PREFIX %} /static/style1.css" type="text/css" />
  <title>Login Page</title>
</head>

<body>
  <form action="/loginpage/" name="myForm" method="post">
    {% csrf_token %}
    <fieldset>
      <legend>Login</legend>
      <br>
      <p style="display:inline">Username</p>
      <br>
      <br>
      <input type="text" name="user" autocomplete="off" placeholder="username" size="30" autofocus required/>
      <br>
      <br>
      <p style="display:inline">Password</p>
      <br>
      <br>
      <input type="password" name="pass" autocomplete="off" placeholder="password" size="30" required/>
      <br>
      <br>
      <input type="submit" name="submit" value="Login" style="height:30px; width:70px" />
      <br>
      <br>
      <p style="font-family:arial; color:#FFFFFF;">{{message}}</p>
    </fieldset>
  </form>
  <br>
  <br>
  <a href="/formlink/" id="sign">Create account</a>
</body>

style1.css

legend {
    border: medium none;
    left: 39%;
    margin: 0 auto;
    padding: 0 10px;
    position: relative;
    text-align: center;
    width: auto;
    color: #FFFFFF;
    font-size: 18px;
    font-weight: bold;
    font: normal 130% 'century gothic', arial, sans-serif;
}

body  {
    background-image: url("12.jpg");
}

fieldset {
    position: absolute;
    left: 600px;
    top: 280px;
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
}

form {
    text-align: center;
}

p {
    font: normal 100% 'century gothic', arial, sans-serif;
    color: #FFFFFF;
}

#home {
    background-color: grey;
    color: #ffffff;
    display: inline-block;
    font-size: 16px;
    margin-left: 20px;
    opacity: 0.9;
    padding: 14px 25px;
    position: absolute;
    text-decoration: none;
    font: normal 100% 'century gothic', arial, sans-serif;
    left: 1450px;
    top: 100px;
}

#home:hover {
    color: black;
    text-decoration: underline;
}

#sign {
    background-color: grey;
    color: #ffffff;
    display: inline-block;
    font-size: 16px;
    margin-left: 20px;
    opacity: 0.9;
    padding: 14px 25px;
    position: absolute;
    text-decoration: none;
    font: normal 100% 'century gothic', arial, sans-serif;
    position: absolute;
    left: 680px;
    top: 650px;
}

#sign:hover {
    color: black;
    text-decoration: underline;
}

1 个答案:

答案 0 :(得分:0)

你已经不遗余力地尝试获取静态前缀,然后你添加了我认为是静态目录的东西,你可以使用static标签

{% get_static_prefix as STATIC_PREFIX %} /static/style1.css

应该是

{% static 'style1.css' %}