【发布时间】:2022-01-09 15:48:53
【问题描述】:
为了使用 django 在 python 中测试模态创建,我创建了一个名为 modalTestApp 的测试应用程序。
然后我复制了我从引导网站上下来的this html 并将其粘贴到应用程序内部的main.html 中,而不更改它。应用程序中的网页加载正常,但单击按钮预览模式没有任何作用。我在这里做错了什么?
main/base.html:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<script src={% static "jquery/jquery-3.3.1.slim.min.js" %}></script>
<script src={% static "jquery/jquery.min.js" %}></script>
<script type="text/javascript" src={% static 'tablesorter-master/js/jquery.tablesorter.js' %}></script>
<script src={% static "bootstrap-4.3.1-dist/js/popper.min.js" %}></script>
<script src={% static "bootstrap-4.3.1-dist/js/bootstrap.min.js" %}></script>
<style type="text/css">
.main {
margin-top: 50px;
padding: 10px 0px;
}
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href={% static "bootstrap-4.3.1-dist/css/bootstrap.min.css" %}>
<title>{% block title %} {% endblock title %}</title>
</head>
<body>
<nav class="navbar navbar-dar bg-dark pb-0 pr-0">
<ul class="nav flex-row">
<p class="navbar-brand mb-0 pt-0" style="color: #eee">Weather Data</p>
<a href="/", class="nav-link active">Home</a>
{% if user.is_authenticated %}
<a href="/stations", class="nav-link active">Stations</a>
{% endif %}
</ul>
<ul class="nav justify-content-end">
{% if not user.is_authenticated %}
<a href="/register", class="nav-link active">Register</a>
<a href="/login", class="nav-link active">Login</a>
{% else %}
<a href="/logout", class="nav-link active">logout</a>
<a href="/users/{{ user.username }}", class="nav-link active">Profile</a>
{% endif %}
</ul>
</nav>
{% block content %}
{% endblock content %}
</body>
</html>
main.html:
{% extends "main/base.html" %}
{%block content %}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
{% endblock content %}
【问题讨论】:
-
您能否添加浏览器控制台的输出,以及关于 Bootstrap JS 和 CSS 文件,您是否将它们添加到该应用程序的静态文件夹中?
-
我收到一条错误消息,说缺少
popper.min.js.map,因此我将<script>行更改为使用cdnjs,但问题仍然存在,所有其他js 和css 文件都可以正常加载。我在 OP 中添加了控制台截图。
标签: django bootstrap-4 bootstrap-modal