繁体   English   中英

django 项目中未加载 CSS 文件

[英]CSS file is not loading in django project

我已经为所有 css 文件添加了静态文件链接。 浏览器中仍然只显示 HTML 文件。 CSS 文件不起作用。 请告诉我是否有任何问题。 如何纠正?

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

索引.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>

样式1.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;
}

您已经竭尽全力尝试获取静态前缀,然后添加我认为是静态目录的内容,您可以只使用static标签

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

应该

{% static 'style1.css' %}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM