[英]Django - JavaScript from static files not loading, but other resources are
I just started playing around with Django and the JavaScript in my static files don't seem to load, while other another resources like logo.png seems to load fine. 我刚刚开始使用Django,并且我的静态文件中的JavaScript似乎没有加载,而其他其他资源(如logo.png)似乎也可以加载。 Am I missing something really basic?
我错过了一些基本的东西吗? Or what I am doing wrong?
还是我做错了什么?
My setup 我的设定
app\\static\\app
as described here app\\static\\app
所描述的在这里 d3.js
) and an image ( logo.png
) in the above directory d3.js
)和一个图像( logo.png
) <script type="text/javascript" href="{% static 'app/d3.js' %}"></script>
<script type="text/javascript" href="{% static 'app/d3.js' %}"></script>
DEBUG = True
(default) DEBUG = True
(默认) Tried solutions 尝试过的解决方案
python manage.py findstatic app/d3.js
python manage.py findstatic app/d3.js
找到文件 STATICFILES_DIRS
as suggested here , but that didn't seem to work. STATICFILES_DIRS
,但这似乎不起作用。 Directory 目录
├───project │ └───__pycache__ └───app ├───migrations │ └───__pycache_ ├───static │ └───app ├───templates │ └───app └───__pycache__
HTML HTML
{% extends 'app/base.html' %} {% load static %} {% block content %} <div id="graphic"></div> <script type="text/javascript" href="{% static 'app/d3.js' %}"></script> <script> D3 things going on here </script> {% endblock %}
Edit : Seems to work when I change the HTML into <script type="text/javascript" src="{{STATIC_URL}}/static/app/d3.js"></script>
编辑 :当我将HTML更改为
<script type="text/javascript" src="{{STATIC_URL}}/static/app/d3.js"></script>
当我将HTML更改为以下内容时,它似乎可以工作: <script type="text/javascript" src="{{STATIC_URL}}/static/app/d3.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.