Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Andréas Kühne
If you use a windows.location solution, you will get the native solution for downloading files in the browser - which usually is to download the file to the downloads location (if you use attachment=True). I would prefer that than to having to create the file and link to it, or to save it via JS (w

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Yavin Aalto Arba
will work with window.location= On Saturday, November 17, 2018 at 5:55:18 PM UTC+2, Joel wrote: > > Yes. But it's not usable when we're using JavaScript to fetch the url. > > On Sat, 17 Nov, 2018, 9:20 PM Jason > wrote: > >> oh, I didn't know that was a thing. TIL. >> >> >> https://docs.djan

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Joel
Yes. But it's not usable when we're using JavaScript to fetch the url. On Sat, 17 Nov, 2018, 9:20 PM Jason oh, I didn't know that was a thing. TIL. > > > https://docs.djangoproject.com/en/2.1/ref/request-response/#django.http.FileResponse > > note the bit about as_attachment setting content disp

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Jason
oh, I didn't know that was a thing. TIL. https://docs.djangoproject.com/en/2.1/ref/request-response/#django.http.FileResponse note the bit about as_attachment setting content disposition -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsu

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Joel Mathew
Where? Sincerely yours, Joel G Mathew On Sat, 17 Nov 2018 at 20:50, Yavin Aalto Arba wrote: > did you try to set "as_attachment=True" ? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receivin

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Yavin Aalto Arba
did you try to set "as_attachment=True" ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Jason
not a bad solution, but you could most likely make the link generator/decoder work in your view handler rather than needing to hit the database. That would prevent the necessity of some method to clean up the db of old temp links that are no longer valid. On Saturday, November 17, 2018 at 9:27

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Joel Mathew
Hi Jason, Thank you for responding. I solved this by implementing a temporary link system in my model. This would generate a unique key which points to a foreign key which references the data I want. When the url with this foreign key is clicked, the pdf is generated on the fly and presented as a F

Re: How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-17 Thread Jason
check out https://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@go

How to download a file when a django function is called by javascript instead of navigation to the url?

2018-11-16 Thread Joel Mathew
I have a page where several buttons process different functions like sending a user sms (via API), sends an file by email, or downloads a PDF file. Button actions dont use forms, but uses ajax requests via javascript. I used to create a pdf file using javascript (jspdf), but have written code whic

Re: How to download a file

2011-11-10 Thread Nikolas Stevenson-Molnar
This document describes how to serve static files in development mode: https://docs.djangoproject.com/en/1.2/howto/static-files/ _Nik On 11/10/2011 11:22 AM, Phanounou wrote: Hello AT, Thanks for your suggestion but I cannot do it this way because I can only developpe with the built-in server

Re: How to download a file

2011-11-10 Thread Phanounou
Hello AT, Thanks for your suggestion but I cannot do it this way because I can only developpe with the built-in server. So that's why I was trying to to send it through response. Do you have a suggestion for that? Thanks again, VB 2011/11/10 Andre Terra > You should serve your files directly t

Re: How to download a file

2011-11-10 Thread Andre Terra
You should serve your files directly through the server (preferably not the built-in django development server), instead of writing a django view. Use nginx[1], apache[2] or any other server, then place the excel file in a directory outside of your django app, and write an alias to that location.

How to download a file

2011-11-10 Thread Virginia
Good day everyone, I'm trying to allow a user to dowload to his machine an excel file from the server. This is my code: wrapper = FileWrapper(open(path_to_file)) content_type = mimetypes.guess_type(path_to_file)[0] response = HttpResponse(wrapper,content_type=content_type)