[英]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. 我下載了包的必要 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 %}
並確保我在該位置有兩個文件,當我嘗試訪問我的站點時,只有當我取消注釋 html 文件中引用 django ZA81259CEF8E959C624DF1D4297E 文件的行時,我才會收到 404 錯誤。
我的 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"),
]
如何讓我的 html 頁面加載這些 static 文件?
看起來 chrome 版本可能不兼容,或者它與 chrome 擴展有關。
您可以做的是使用以下代碼阻止background.js :
$(document).ready(function(){
$.getScript("urlofscript");
});
獲取URL, hover on the background.js寫在檢查菜單上。
希望這可以幫助!
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.