简体   繁体   English

Django 为什么我的 static JS 文件没有加载

[英]Django why my static JS files not loading

I have a django project I am working on, and I am pretty new to Django and Python in general.我有一个正在处理的 django 项目,总的来说,我对 Django 和 Python 还是很陌生。 I have created my base.html as the following:我创建了我的 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>

After that I have created my _scripts.html file as the following:之后,我创建了我的 _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 %}

Now I want to to add in a new html file named example.html a chart created with charts.js.现在我想在名为 example.html 的新 html 文件中添加一个使用charts.js 创建的图表。 Now I have created it and added in the example.html.现在我已经创建它并添加到示例中。html。 But If I try to created a new js file (named graph.js) in my static folder does not work.但是如果我尝试在我的 static 文件夹中创建一个新的 js 文件(名为 graph.js)将不起作用。 In which part of my code I have to insert <script src="{% static "grafici/graph.js" %}"></script> to load it correctly?我必须在代码的哪一部分插入<script src="{% static "grafici/graph.js" %}"></script>才能正确加载它?

this my setting:这是我的设置:

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT= '/static/'

Try to run this CMD """ python manage.py collectstatic """尝试运行这个 CMD """ python manage.py collectstatic """

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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