如何将 Django 静态文件放入 javascript 数组?
How can I put django static files in javascript array?
我需要从 Django 获取静态文件到 "links" 数组...
var links = [
'/static/uploads/fth/FthAgg.xlsx',
'/static/uploads/fth/FthCon.xlsx'
];
这是html:
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="{% static 'css/pages/fthpage.css' %}">
<script src="{% static 'js/downloads.js' %}"></script>
<title></title>
</head>
<body>
<h1 class="header_h1">FTH Page</h1>
<button onclick="downloadAll(window.links)">Test me!</button>
</a>
</body>
</html>
但这行不通。当我尝试放置 https 链接时,它会起作用。
我这样做是为了以后可以通过一个按钮同时下载这些文件。
这是我的 javascript 文件:
https://pastebin.com/0sCTav8G
这是我的 html 模板:
https://pastebin.com/yvz2AL0M
function downloadAll(links)
{
for (i = 0, len = links.length; i < len; i++) {
var link = links[i];
var a = document.createElement("a");
var file = 'file'+ i + '.xlsx';
a.setAttribute('href', 'data:text/plain;charset=utf-8, '
+ link);
a.setAttribute('download', file);
a.click();
}
}
我需要从 Django 获取静态文件到 "links" 数组...
var links = [
'/static/uploads/fth/FthAgg.xlsx',
'/static/uploads/fth/FthCon.xlsx'
];
这是html:
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="{% static 'css/pages/fthpage.css' %}">
<script src="{% static 'js/downloads.js' %}"></script>
<title></title>
</head>
<body>
<h1 class="header_h1">FTH Page</h1>
<button onclick="downloadAll(window.links)">Test me!</button>
</a>
</body>
</html>
但这行不通。当我尝试放置 https 链接时,它会起作用。 我这样做是为了以后可以通过一个按钮同时下载这些文件。
这是我的 javascript 文件: https://pastebin.com/0sCTav8G
这是我的 html 模板: https://pastebin.com/yvz2AL0M
function downloadAll(links)
{
for (i = 0, len = links.length; i < len; i++) {
var link = links[i];
var a = document.createElement("a");
var file = 'file'+ i + '.xlsx';
a.setAttribute('href', 'data:text/plain;charset=utf-8, '
+ link);
a.setAttribute('download', file);
a.click();
}
}