如何将文件保存在用户本地目录而不是烧瓶中的服务器上?

我创建了一个Web应用程序,用户可以在该应用程序中以.xlsx格式从雅典娜下载报告。

当我在系统上托管应用程序时,用户可以访问我的烧瓶的网页,但是当用户下载报告时,报告将保存在我的系统中。

当我尝试更改位置或其他方法时,出现内部服务器错误

'''

CGIHandler().run(app)


app = flask(__name__)



def colorExcle(loc):
    wb = Workbook()
    location = loc


    redFill = PatternFill(start_color='99e6ff',end_color='99e6ff',fill_type='solid')

    ws = wb.active
    wb = openpyxl.load_workbook(location)

    sheet = wb['Sheet1']
    sheet.cell(row=1,column=11).value = 'username'
    sheet.cell(row=1,column=12).value = 'Result'
    sheet.cell(row=1,column=13).value = 'Coding Time in min'
    sheet.cell(row=1,column=14).value = 'QC1 By'
    sheet.cell(row=1,column=15).value = 'QC1 Result'
    sheet.cell(row=1,column=16).value = 'QC1 Time in min'
    sheet.cell(row=1,column=17).value = 'Comments'
    sheet.cell(row=1,column=18).value = 'KM'
    sheet.cell(row=1,column=19).value = 'Rework'
    sheet.cell(row=1,column=20).value = 'QC2 Time in min'
    sheet.cell(row=1,column=21).value = 'QC2 Results'



    sheet.cell(row=1,column=1).fill = redFill
    sheet.cell(row=1,column=2).fill = redFill
    sheet.cell(row=1,column=3).fill = redFill
    sheet.cell(row=1,column=4).fill = redFill
    sheet.cell(row=1,column=5).fill = redFill
    sheet.cell(row=1,column=6).fill = redFill
    sheet.cell(row=1,column=7).fill = redFill
    sheet.cell(row=1,column=8).fill = redFill
    sheet.cell(row=1,column=9).fill = redFill
    sheet.cell(row=1,column=10).fill = redFill
    sheet.cell(row=1,column=11).fill = redFill
    sheet.cell(row=1,column=12).fill = redFill
    sheet.cell(row=1,column=13).fill = redFill
    sheet.cell(row=1,column=14).fill = redFill
    sheet.cell(row=1,column=15).fill = redFill
    sheet.cell(row=1,column=16).fill = redFill
    sheet.cell(row=1,column=17).fill = redFill
    sheet.cell(row=1,column=18).fill = redFill
    sheet.cell(row=1,column=19).fill = redFill

    sheet.cell(row=1,column=20).fill = redFill
    sheet.cell(row=1,column=21).fill = redFill
    wb.save(location)   

    return render_template('index.html')





@app.route('/',methods = ['GET','POST'])

def index():

    if "HAD" in request.form:

        projectTag = request.form.get('projectTag')
        region = request.form.get('region')

        if request.method == "POST":
            region = request.form.get("region",None)
            if region!=None:

                conn = connect(aws_access_key_id='xxxxxxxxxxxxxxxxxxxxxxxxx',aws_secret_access_key='xxxxxxxxxxxxxxxxxxxxxxxxxxx',s3_staging_dir='s3://xxxxxxxxxxxxxxxxxxxxxx/',region_name='us-west-1')


                username = getpass.getuser()

                cursor = conn.cursor()
                now = datetime.today().strftime("%d-%m-%y")
                excelName=region.upper()+"_"+projectTag+"_"+now
                wb = Workbook()
                ws = wb.active

                data1 = r"C:\\Users\\"+ getpass.getuser()+"\\Downloads\\"+excelName+'.xlsx'


                wb.save(data1)
                wb = openpyxl.load_workbook(data1)
                sheet = wb['Sheet']
                data =  pd.read_sql("SELECT * from geocord;",conn)
                data.to_excel(data1)

                return colorExcle(data1)
                return render_template('index.html',projectTag,region)


    return render_template('index.html')


@app.route('/home','POST'])



@app.route('/about')
def about():
    return render_template('about.html')



if __name__ == "__main__":

    app.run(host="192.168.0.103",port=80)

'''

我也使用过: '''     路径=“ C:\ flask”

return send_file(path,as_attachment=True)

''' 出现错误为: cmd: PermissionError:[Errno 13]权限被拒绝 网页:内部服务器错误 服务器遇到内部错误,无法完成您的请求。服务器过载或应用程序出现错误。

由于我是flask框架的新手,所以描述性代码将为我提供更多帮助。

lxmforyou 回答:如何将文件保存在用户本地目录而不是烧瓶中的服务器上?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3131610.html

大家都在问