如何在web2py中控制图像的文件名?

时间:2011-01-11 11:55:58

标签: image png filenames user-input web2py

我使用了以下行 图像= URL(R =请求中,f = 'nonhomog_plot') 在web2py中制作图像。图像的文件名为“nonhomog_plot.png”。如何控制图像的文件名?我希望文件名包含用户输入变量+“_Figure1.png”。

1 个答案:

答案 0 :(得分:3)

请在web2py邮件列表中提出这些问题。那是专家们的。在这里,您倾向于获得可能不是web2py专家的人的通用答案。无论如何。

image=URL(r=request,f='nonhomog_plot')

可以改写为

image=URL('nonhomog_plot.png')

我假设nonhomog_plot是一个流式传输文件的web2py动作。

之类的东西
def nonhomog_plot():
    return response.stream(open('filename.png','rb'))

现在你可以添加

def nonhomog_plot():
    filename='Figure1.png'
    response.headers['Content-Disposition']='attachment; filename='+filename 
    return response.stream(open('filename.png','rb'))