BOOTSTRAP //尽管添加了cdn链接和引用样式链接// PYTHON但仍无法正常工作

时间:2018-06-06 09:03:38

标签: python html django twitter-bootstrap cloud9

我目前正在构建这个Django app,在我得到了我想要的主要部分,即登录页面和主页工作后,我决定更新我的页面外观,因为它是非常基本的。我之前使用过自行车,我爱上了它。但是,这个问题对我来说是第一个问题。正如您将在下面看到的那样,我通过CDN(TWICE)和引用样式表链接链接了bootstrap。尽管所有这些不同的获取引导方式我的页面仍然看起来像这样

my page still looks like this

这是我的base_generic.html

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>

    {% block title %}<title>Local Library</title>{% endblock %}
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">-->
  <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>-->
  <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->


    <!-- Add additional CSS in static file -->
    {% load static %}
    <link rel="stylesheet" href="{% static 'css/styles.css' %}">
    <!--<img src="{% static 'catalog/images/local_library_model_uml.png' %}" alt="My image" style="width:555px;height:540px;"/>-->
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" />

</head>

<body>
    {% include "header.html" %}


    <div class="jumbotron">
        <div class="container">
            {% block content %}{% endblock %}
            {% include "pagination.html" %}
        </div>
    </div>
</body>
</html>

这是我的header.html文件,其中包含我的导航栏

{% load staticfiles %}

<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
      <a class="navbar-brand" href="#">Navbar</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
          <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="#">Link</a>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled" href="#">Disabled</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
            <div class="dropdown-menu" aria-labelledby="dropdown01">
              <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>
        <form class="form-inline my-2 my-lg-0">
          <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
          <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
        </form>
      </div>
    </nav>

继承我文件结构的样子

Framework

任何输入或反馈都会有所帮助。我真的被困在这里了。

3 个答案:

答案 0 :(得分:1)

将此添加到settings.py`STATICFILES_DIRS = [os.path.join(BASE_DIR,'static'),]

答案 1 :(得分:0)

正如你在Bootstrap无法正常工作的问题中所提到的,但是在页面上,它显示了Bootstrap样式,例如Jumbotron Background和按钮颜色。那么,你怎么能说bootstrap不起作用?请澄清你的问题。

答案 2 :(得分:0)

<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

将其放在head标签中,为我解决了这个问题。