简体   繁体   English

clusterize.js 与 django; 未找到 static 文件

[英]clusterize.js with django; static files not found

I am trying to use the https://clusterize.js.org/ javascript package with my Django website for displaying extremely large tables neatly and speedily. I am trying to use the https://clusterize.js.org/ javascript package with my Django website for displaying extremely large tables neatly and speedily. I downloaded the package's necessary js and css files, and referenced them in the html getting loaded when i visit my site's url: mysite.com/popularify我下载了包的必要 js 和 css 文件,并在访问我网站的 url 时加载的 html 中引用了它们:mysite.com/

{% load static %}

{% block content %}
<!DOCTYPE html>
<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

    <!-- uncommenting this line loading status files causes errors 
    <script src="{% static 'js/clusterize.min.js' %}"></script>
    -->

    <!-- I have a static/js/ folder -->

</head>

<body>
    <div>
        arthur russell = spotify:artist:3iJJD5v7oIFUevW4N5w5cj <br>

    <!--HTML-->
    <div class="clusterize">
        <table>
            <thead>
                <tr>
                    <th>Headers</th>
                </tr>
            </thead>
        </table>
        <div id="scrollArea" class="clusterize-scroll">
            <table>
                <tbody id="contentArea" class="clusterize-content">
                    <tr class="clusterize-no-data">
                        <td>Loading data…</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <script>

        // clusterize JavaScript
        var data = ['<tr>x</tr>', '<tr>z</tr>', '<tr>zxc</tr>'];
        var clusterize = new Clusterize({
            rows: data,
            scrollId: 'scrollArea',
            contentId: 'contentArea'
        });

    </script>

</body>

</html>
{% endblock content %}

And ensured that I have the two files in that location, when I try to access my site i am getting a 404 error only when I uncomment the line in my html file referencing the django static file.并确保我在该位置有两个文件,当我尝试访问我的站点时,只有当我取消注释 html 文件中引用 django ZA81259CEF8E959C624DF1D4297E 文件的行时,我才会收到 404 错误。

My settings.py Django file has:我的 settings.py Django 文件有:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static"),
    ]

How can I make my html page load these static files?如何让我的 html 页面加载这些 static 文件?

Looks like chrome version may not be compatible or it has something to do with the chrome extensions.看起来 chrome 版本可能不兼容,或者它与 chrome 扩展有关。

What you can do is to block background.js using this code:您可以做的是使用以下代码阻止background.js

$(document).ready(function(){
    $.getScript("urlofscript");
});

To get the URL, hover on the background.js written on the inspection menu.获取URL, hover on the background.js写在检查菜单上。

Hope this helps!希望这可以帮助!

You path to other static files also doesn't seem to be correct Django template support staticfile tag , so in your template at the top add load staticfile and include the static tag and the path is inside your static folder like so: You path to other static files also doesn't seem to be correct Django template support staticfile tag , so in your template at the top add load staticfile and include the static tag and the path is inside your static folder like so:

{% load staticfiles %}

<link rel="stylesheet" href="{% static 'css/main.css' %}">

<script src="{% static 'js/custom.js' %}"></script>

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

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