[mod_python] req.sendfile(): specifying a name for the file sent?

Adrian Holovaty modpython at holovaty.com
Mon May 9 19:18:42 EDT 2005

Calvin Chen wrote:
> Right now, when I use req.sendfile(), the file download prompt comes
> up and asks me if I want to download a file. So far so good. The
> contents of this file is exactly how I wanted it to be. So far so
> good.

You'll want to send out the "Content-Disposition" header. Set its value to 

"attachment; filename=name.txt"

...where "name.txt" is whatever you want the filename to be.

In your example, the code would be:

def index(req):
    req.headers_out['Content-Disposition'] = 'attachment; filename=name.txt'

Hope this helps!



More information about the Mod_python mailing list