django动态加载静态文件

时间:2020-04-23 14:05:13

标签: django django-templates django-staticfiles

我正在尝试将静态链接发送到下载按钮。静态链接产生一个views.py函数,并将作为字典返回。

in views.py:
def some_fct(request):
    handling the request
    return render(request,'site.html',{'processed_request': 'name_of_static_file'})

我试图在单独的div中定位数据,并使用以下方式更改href:

<div id="data">{{processed_request}}<\div>
<a href="" id="download"><button class="download_btn"><i class="fa fa-download"></i> Download</button></a>

<script>
let file = document.getElementbyId('data').innerHTML; 
let file_static = "{% static '${file}' %}"   
document.getElementById('download').setAttribute("href",file_static);
</script>

通向console.log

https://..../static/%24%7Bfile%7D

代替

https://..../static/name_of_static_file

如何访问static_file?

0 个答案:

没有答案