html文件没有扩展

时间:2018-02-16 12:04:42

标签: django django-templates

我扩展了基本文件,目录是正确的,Iam仍然是正常的样式。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Isai</title>
    {% load staticfiles %}
    <link rel="stylesheet" href="{% static 'personal/css/bootstrap.min.css' %}" type = "text/css"/>
    <link href='http://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="{% static 'music/Stylesheet.css' %}" type = "text/css"/>
</head>
<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Features</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Pricing</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
  </div>
</nav>
{% block body %}
{% endblock %}
</body>
</html>

这是基础html.I从bootstrap 4.0复制了这个。我也包含了bootstrap的静态文件。昨天它运行正常。但今天它不能正常工作

{{1}}

1 个答案:

答案 0 :(得分:3)

好像您将 templates static 资产存储在同一目录中:

{% extends "music/base.html" %} 
<link rel="stylesheet" href="{% static 'music/Stylesheet.css' %}" type = "text/css"/>

由于您提到模板正在加载,我想music文件夹是您的模板文件夹

您需要为静态资产(css,js等)创建一个文件夹。

通常我们将其存储在:

/static/css/

将它们存放在不同的地方也是一个好主意。

完成此操作后,将Stylesheet.css文件移至/static/css/

不要忘记将此文件夹添加到 settings.py 中的STATICFILES_DIRS配置中。

<强> settings.py

STATICFILES_DIRS = (
    os.join(BASE_DIR, 'static'),
)

然后你可以更新你的css参考:

<link rel="stylesheet" href="{% static 'css/Stylesheet.css' %}" type = "text/css"/>

您可以阅读有关static files management on the docs的更多信息。