我開發了一個數據科學web應用程序,可以生成各種統計分析相關的圖表。統計函數從Django應用程序執行,名爲「ProtocolApp」,其中我有一個目錄爲「Statistical_protocols」,而「Stat_Learning」項目爲基目錄。我的程序正在生成一些圖像文件和.csv輸出文件,其中包含項目「Stat_Learning」的基本目錄,「manage.py」存在的同一目錄「。如何在Django中爲下載鏈接添加一個目錄?
在模板中,我提供了所有文件的鏈接這樣的:
模板:
{% extends 'protocol/base.html' %}
{% load static %}
{% block content %}
<style type="text/css">
table {
margin-bottom: 20px;
border-collapse: collapse;
border-spacing: 0;
width: 30%;
border: 1px solid #ddd;
bgcolor: #00FF00;
}
th, td {
border: none;
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
</style>
<div style="overflow-x:auto;">
<table align="center">
<tr>
<th align="center">Result files</th>
</tr>
{% for a in names %}
<tr>
{% if a %}
<td><a href="/virtual_env_dir/Base_rectory_of_the_project/{{a}}"> {{a}} </a> <br></td>
{% endif %}
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
有沒有爲所有文件提供通過這個基本目錄下載鏈接的方法
或有添加另一個名爲「下載」等目錄中的任何方法然後媒體目錄。因爲我正在使用媒體目錄上傳協議的輸入文件。
感謝
你能解釋一點,這是怎麼回事這裏我很新,所以它很難對我來說,在我的情況 – jax
這就是如何申請文件下載在適應這個代碼Django的。您可能需要閱讀https://docs.djangoproject.com/en/1.10/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment –
但我沒有類似的文件到服務器,所以我可以定義不同的文件作爲內容類型。 – jax