I want to create views to download multiple files. This view downloads a single file. But, I have to create the views to download all the files in the list.
def submit(request):
# converts files and make new output files.
paths = [# list of files]
base_names = [os.path.basename(path) for path in paths]
path = paths[0]
# paths, path both are in context
def download(request):
path = request.GET.get('path')
base_name1 = os.path.basename(path)
context = {'path': path, 'base_name1': base_name1}
with open(path, 'rb') as fh:
response = HttpResponse(fh.read())
response['Content-Disposition'] = 'inline; filename='+base_name1
return response
The following template downloads a single file that is in the paths list. I want to create a template view that lists all the files in the paths list and download them. Any ideas or suggestions for this.
template code:
<p>You have successfully converted the file. </p>
<p>Code : {{ code }} </p> #values returned from context
<p>Number : {{ number }}</p> #values returned from context
<p> <a href ="{% url 'download' %}?path={{ path|urlencode }} " download>{{ base_name }} </a> </p>