2017-01-15 65 views
-1

我已經提到了有關文件下載的多個django問題,並且這是建議的解決方案。在djano中生成下載鏈接

{% for task in tasks %} 
      <tr><td><strong> name {{task.name}}</strong></td>   
      <td><strong> date {{task.date_created}}</strong></td> 
      <td><strong> status {{task.status}}</strong></td> 
      <td><strong> id {{task.id}}</strong></td> 
      <td><strong> input file {{task.input_file_path}}<td> 
      <td><a href="{{task.output_file_path}}" download>output file</td></tr> 
      {% endfor %} 

提出的解決方案是<a href="{{task.output_file_path}}" download>然而,當我檢查我的Django的請求。它在控制檯中顯示出來。 GET /adv_filters/check/download/download/download/download/download/download/download/download/download/download/download/download/download/download/download/download/download/download/download/download/input_files/input_files/input_files/input_files/input_files/task4 HTTP/1.1" 200 2524

出於測試目的。我已將輸出文件的位置設置爲輸入文件的位置。

我有關views.py

document.input_file_path = 'input_files/' + document.name 
      document.output_file_path = 'input_files/' + document.name 

Models.py

doc = models.FileField(upload_to='input_files') 

有沒有了信息,我需要。

+0

能否請您分享您的媒體從settings.py –

+0

設置我沒有爲它 – aceminer

+0

任何特定的環境,我認爲這就是問題所在。您需要設置媒體文件位置和媒體網址。 –

回答

1

我想簡單地把文件鏈接(即我假設{{task.output_file_path}}是)應該工作。

<td><a href="{{task.output_file_path}}"</a> Download output file</td>