On Wed, Mar 20, 2013 at 2:50 AM, Branko Majic <bra...@majic.rs> wrote:
> On Tue, 19 Mar 2013 19:27:33 -0600
> Larry Martell <larry.mart...@gmail.com> wrote:
>
>> On Tue, Mar 19, 2013 at 7:07 PM, Tim Chase
>> <django.us...@tim.thechases.com> wrote:
>> > On 2013-03-19 18:42, Larry Martell wrote:
>> >> https://docs.djangoproject.com/en/dev/howto/outputting-pdf/ which
>> >> says to use the Content-disposition header to trigger the save as.
>> >> I've done this, but I don't get a save as dialog box. The file is
>> >> just downloaded to a download dir with the name I have provided.
>> >>
>> >> Is there a way I can specify from my app what directory I want the
>> >> file saved to?
>> >
>> > I believe this is a browser-configuration setting controlled by the
>> > user, not by HTTP metadata.  In Firefox, I have the option to either
>> > open the file or save the file, along with a check-box to "always do
>> > this"; FF also provides me the control to specify where the file
>> > goes on a per-download basis, or to default to a given location.
>> >
>> > tl;dr: I don't think your web-app can take away this control from
>> > the user.
>>
>> That's what I thought, but my client wants the file saved to a
>> specific location. This is an internal app, not something for public
>> usage. Perhaps I can pass the file back in a context and save it from
>> javscript.
>>
>
> I'd be very surprised if you could use JavaScript to do something like
> that. It would've been considered a security vulnerability by any
> browser software vendor out there.
>
> If client wants the file to be saved to specific location, you should
> probably try to direct them to some specific solution for the browser
> of their choice. For Firefox you should be able to find some extensions
> that can automatically save files to certain directories based on file
> type. Maybe there's something out there that could do so based on MIME
> type (Content-Disposition) set for the file (so you can set something
> other than PDF for it in order to have other website PDFs saved to
> other locations).
>
> If you are really persistent, you could try using some kind of Flash
> thing or Java applet, but that's a very, very, very, very bad idea.
>
> So, you'll probably left with negotiating it with your client not to
> insist on that, or see if you can tweak the browser settings in some
> way (most probably with an extension) :)

Yes, I have convinced them to not require this. Now my issue is how to
cause a file to be saved and to also render a template. When I return
this:

        response = HttpResponse('This is what I want to save')
        response['Content-Type'] = 'application/gzip'
        response['Content-disposition'] = 'Attachment; filename=export.gzip'
        return response

my template is obviously not rendered. How can I do this and also
render my template at the same time?

-- 
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 email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to