Open a file from a network drive django in a new tab

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Open a file from a network drive django in a new tab on this date .

I’m trying to have a table that opens an invoice in a new tab but I’m not getting on how to use the url format to have the mapping done to a shared network folder.

enter image description here

I’m trying by doing the following in the table definition

  <tbody>
  {% for datarow in dataset %}
  <tr>
    <td>{{datarow.supplierName}}</td>
    <td>{{datarow.invoiceNumber}}</td>
    <td>{{datarow.reference}}</td>
    <td><a href = "open(r'\REMOTESERVERShared1FOLDERFOLDER Images{{datarow.docId|urlize}}file.tiff')">Open Invoice</a>
    {% endfor %}
  </tr>
  </tbody>

however it doesn’t open as the url still tries to map from localhost.

Also in each folder I have one .tiff file but other files as well, I’m also looking into having a way to open that .tiff file (different name per folder) to be used in the url but I haven’t got there yet.

note: my datarow.docId is the folder name in the network drive. Also I’ve read that it might have to be done with Pathlib, however I don’t get how to do it if so.

Answer

I was able to solve this by setting the shared drive in the “STATICFILES_DIRS” list and then

{% load static %}
    {% static "" %}{{ datarow.docud }}/file.tiff

to call in the template for the static path