[英]Django why my static JS files not loading
我有一个正在处理的 django 项目,总的来说,我对 Django 和 Python 还是很陌生。 我创建了我的 base.html 如下:
{% load adminlte_helpers i18n %}
{% load static %}<!DOCTYPE html>
<html>
<head>
{% block stylesheets %}
{% include 'adminlte/lib/_styles.html' %}
{% endblock %}
{% block body %}
....
{% endblock body %}
{% block javascript %}
{% include 'adminlte/lib/_scripts.html' %}
{% endblock %}
{% block extra_js %}
{% endblock %}
</body>
</html>
之后,我创建了我的 _scripts.html 文件,如下所示:
{% load static %}
{% block scripts %}
<script src="{% static 'admin-lte/plugins/jquery/jquery.min.js' %}"></script>
<script src="{% static 'admin-lte/plugins/jquery-ui/jquery-ui.min.js' %}"></script>
<script src="{% static 'admin-lte/plugins/chart.js/Chart.min.js' %}"></script>
<script src="{% static 'admin-lte/plugins/bootstrap/js/bootstrap.bundle.min.js' %} "></script>
{% block datatable_js %}{% endblock %}
{% endblock %}
现在我想在名为 example.html 的新 html 文件中添加一个使用charts.js 创建的图表。 现在我已经创建它并添加到示例中。html。 但是如果我尝试在我的 static 文件夹中创建一个新的 js 文件(名为 graph.js)将不起作用。 我必须在代码的哪一部分插入<script src="{% static "grafici/graph.js" %}"></script>
才能正确加载它?
这是我的设置:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT= '/static/'
尝试运行这个 CMD """ python manage.py collectstatic """
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.