[英]Django can't load javascript but load css (include link to project)
Please your help.. I spent hours to understand it请你的帮助..我花了几个小时来理解它
I started a very basic template with Django, and it can't find my js files, while it can find the css file - when both of them in static folder我用 Django 开始了一个非常基本的模板,它找不到我的 js 文件,而它可以找到 css 文件- 当它们都在 static 文件夹中时
Here is a link for the project (1.4MB) 这是该项目的链接(1.4MB)
Thanks a lot!非常感谢!
[11/Jun/2020 00:21:18] "GET /js/init.js HTTP/1.1" 404 2134
Not Found: /js/materialize.js
[11/Jun/2020 00:21:18] "GET /js/materialize.js HTTP/1.1" 404 2155
Not Found: /js/init.js
In Setting.py I have these settings:在 Setting.py 我有这些设置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = 'staticfiles'
My Page index.html:我的页面索引.html:
This is my Project Dictionary: 3 folders - (1) home [the app] (2) project_folder (3) static - contain css, js, images这是我的项目词典: 3 个文件夹 - (1) 主页 [应用程序] (2) project_folder (3) static - 包含 css、js、图像
Found it.找到了。 Obviously it was a small mistake that messed with the whole thing:
显然,这是一个小错误,搞砸了整个事情:
Even though I've added the JS at the top correctly like this:即使我已经像这样在顶部正确添加了 JS:
<head>
...
<!-- JS -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script type="text/javascript" src="https://drive.google.com/uc?export=view&id=11SXwFQpXEPJB6y_0aExroDW6VD97egRb"></script>
</head>
I had this code at the end of the HTML:我在 HTML 的末尾有这个代码:
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/init.js"></script>
</body>
</html>
Fixed by:修复者:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.