为什么我的django4静态JavaScript不起作用



My html:

{% load static %}
<!doctype html>
<html lang="en">
<head>


<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap-grid.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap-reboot.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap.min.css' %}" />
<!-- Own CSS -->
<link rel="stylesheet" type="text/css" href="{% static 'news/css/base.css' %}" />
</head>
<body>

<div class="topnav" id="myTopnav">
<a href="#home" class="active">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<div class="dropdown">
<button class="dropbtn">Dropdown 
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div> 
<a href="#about">About</a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a>
</div>
<div style="padding-left:16px">
<h2>Responsive Topnav with Dropdown</h2>
<p>Resize the browser window to see how it works.</p>
<p>Hover over the dropdown button to open the dropdown menu.</p>
</div>

<!--First own js, then other js-->

<script type="text/javascript" src="{% static 'news/js/base.js' %}"></script>
<script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
</body>
</html>

我的目录:

博客--新闻

--模板

--静态

----引导

------css

------js

----新闻

------css

--------base.css

------js

--------base.js

--介质

设置和URL:

MEDIA_URL='/MEDIA/'MEDIA_ROOT=os.path.join(BASE_DIR,'MEDIA'(

STATIC_URL='/STATIC/'STATIC_DIR=os.path.join(BASE_DIR,'STATIC'(STATICFILES_DIRS=[STATIC_DIR,]

urlpatterms+=staticfiles_urlpatterms((if settings。调试:URL模式+=静态(settings.MEDIA_URL,document_root=settings.MDIA_root(urlpatters+=静态(settings.static_URL,document_root=settings.static_root(

my-base.js:

function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}

只需设置类似的静态路径

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR /'static']
# ---------- OR -----------------------
import os
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]

最新更新