我的导航栏未在我的项目中扩展。为了排除故障,我确实做了一个新的简化项目,并且在那儿运行良好。因此,我不确定这是什么问题。这是无效的代码:
shopping = [ 'Garlic', 'Califlower', 'Peppper', 'Slat', 'Oil', 'Beer', 'Toilet Paper', 'Pizza' ]
if 'Mashrum' not in shopping:
print('we missed Mashrum!')
因此,我将粘贴的nav元素复制到另一个文件中。使用几乎相同的代码:
<head>
<meta charset="utf-8">
<meta http-equiv = "X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width", initial-scale=1>
<title> My Project
</title>
<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.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" ></script>
</head>
<body>
<nav class="navbar navbar-expand-md bg-light navbar-flex navbar-dark">
<div class="container-fluid">
<!-- 1) Brand -->
<div class="navbar-brand">
<a hreft="{% url 'dashboard' %}">
<img src="logo.jpg" id="logo_sample" class="logo img-responsive navbar-padding navbar_top_padding pull-left" alt="Logo image">
</a>
</div>
<!-- 2) Toggle Button -->
<button id="myButton" type="button" class="navbar-toggler align-self-center " data-target="#navbarNav" data-toggle="collapse"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- 3) Collapsible List -->
<section class="collapse navbar-collapse" id="navbarNav">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link" href="{% url 'accounts:login' %}"> Log in</a>
<a class="nav-item nav-link" href="{% url 'accounts:signup' %}"> Sign up</a>
<a class="nav-item nav-link" href="http://www.example.com/about">About Us</a>
<a class="nav-item nav-link" href = "http://www.example.com/contact">Contact us</a>
</div>
</section>
</div>
</nav>
...
</body>
但是,它在此文件中有效。导入是相同的,代码段是相同的,那么为什么会有行为上的差异?感谢您的帮助