简体   繁体   English

Django-无法加载静态文件中的JavaScript,但其他资源

[英]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 我的设定

  • Using Docker with Python 3.5 with and Django 2.1 as described here 使用泊坞窗与Python 3.5和2.1 Django的描述在这里
  • My static files are in app\\static\\app as described here 我的静态文件是在app\\static\\app所描述的在这里
  • I have a JavaScript file ( d3.js ) and an image ( logo.png ) in the above directory 我在上面的目录中有一个JavaScript文件( d3.js )和一个图像( logo.png
  • In my template I have <script type="text/javascript" href="{% static 'app/d3.js' %}"></script> 在我的模板中,我有<script type="text/javascript" href="{% static 'app/d3.js' %}"></script>
  • In settings.py I have DEBUG = True (default) 在settings.py中,我的DEBUG = True (默认)
  • On a Windows environment 在Windows环境中

Tried solutions 尝试过的解决方案

  • I can find the files with python manage.py findstatic app/d3.js 我可以使用python manage.py findstatic app/d3.js找到文件
  • I tried adding 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM