skip to Main Content

I need the .wav file that is created in the "static" folder to be able to be downloaded via a link inserted via HTML or viewed via FileResponse.

I tried things like:

<a href="{% static 'files/{{ filename }}' %}">Download: {{ filename }} </a>

But this didn’t work because it doesn’t find the resource.

2

Answers


  1. You try this code to solve your issue:

    <a href="{% url 'download_wav' filename='your_wav_filename.wav' %}">Download .wav File</a>
    
    Login or Signup to reply.
  2. As others pointed out make sure where to store your files.

    After that You should add download attribute to your anchor tag. link

    The download attribute specifies that the target (the file specified in the href attribute) will be downloaded when a user clicks on the hyperlink.

    The optional value of the download attribute will be the new name of the file after it is downloaded.

    static files:

    <a href="{% static 'files/{{ filename }}' %}" download="{{ filename }}">Download: {{ filename }} </a>
    

    media files:

    <a href="{{ dynamic_filename_url }}" download="{{ filename }}">Download: {{ filename }} </a>
    

    If you store your media files in the filesystem of your django app, you can use url tag

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search