Edinburgh-Genome-Foundry / CAB

:oncoming_taxi: The friendly Computational App Boilerplate. Django + Vue.JS + Redis queues + NginX
Other
22 stars 4 forks source link

How to create a url entry for downloading a result csv file? #8

Open usccolumbia opened 4 years ago

usccolumbia commented 4 years ago

My app generated a result csv file 123.csv and I put it into the backend/app/data folder

I created a link in the result page as http://localhost/download/123.csv

then I create this url entry in backend/website/urls.py

url(r'^api/download/<str:filename>$', views.download_file, name="download")

and defined the download_file view function in backend/app/views/init.py

def download_file(request, filename): print("**** download_file function ..........") response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="export.csv"' writer = csv.writer(response) writer.writerow(['id', 'EmpID', 'BarID', 'Username', 'Type', 'Liability', 'Date'])

for item in data:

#     writer.writerow([item.id, item.EmpID, item.BarID, item.Username, item.Type, item.Liability, item.Date])
return response

However, when I click the link url http://localhost/download/123.csv

it reports Cannot GET /download/123.csv and it did not trigger my download_file view function it seems did not map the url successfully to the view function. download_file()

How should I set the url entry to map the http://localhost/download/123.csv link to the download_file() function?

Thanks

George