Can I set the filename to which a file is being downloaded to?
I have a bunch of files, that are being uploaded and tagged by users. When another user downloads one of those files, I want to create a filename like this:
creator_tag1_tag2_name.ext
How can I do that? Does this have to happen on Django side or can it b开发者_开发百科e done via jQuery?
In your Django view corresponding to your download, you can set the content disposition header:
response['Content-Disposition'] = 'attachment; filename=somefilename.jpg'
A more detailed answer is given here:
- Having Django serve downloadable files
You need to set returned HTTP header as something like the following:
response.headers['Content-disposition'] = 'attachment; filename=creator_tag1_tag2_name.ext'
精彩评论