为什么我的 html 文件没有获取我的 javascript 文件。静态负载
这是我的settings.py:
STATIC_DIR = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIR = [STATIC_DIR]
这是我的html页面的末尾:
{% load static %}
<script src="{% static '/js/script.js' %}" type="text/javascript"></script>
</html>
{% endblock %}
我有一个文件夹static
,里面还有两个文件夹,一个是js
,另一个是js
是css
。但是当我尝试加载它时,它总是显示 "GET /static/js/script.js HTTP/1.1" 404 1795
我已经尝试了很多方法,但它不起作用。请有人帮忙。
here is my settings.py:
STATIC_DIR = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIR = [STATIC_DIR]
here is the end of my html page:
{% load static %}
<script src="{% static '/js/script.js' %}" type="text/javascript"></script>
</html>
{% endblock %}
I have a folder static
and inside it, there are two more folders one is js
and the other is css
. But when I try to load it, it always says "GET /static/js/script.js HTTP/1.1" 404 1795
I have tried many things but it does not work. Someone please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它是开发服务器(即DEBUG = True),则尝试以下操作:
如果它是生产服务器,则只需删除
STATICFILES_DIR
。 官方文档更深入地解释了这一点。If it is development server (i.e DEBUG = True), then try this:
If it is production server, then you simply remove the
STATICFILES_DIR
. The official documentation explains this more in depth.