传递参数以从烧瓶中的app.run()传入

时间:2019-10-16 06:25:58

标签: python flask

我正在使用flask服务器下载文件, 我想从启动服务器方法将file_path传递给函数upload_file filepath参数, 我如何从app.run()方法传递文件路径。

def start_server(get_param):
    host = get_param['host']
    port = get_param['port']
    file_path = get_param['file_path']
    print('\nhost :: ',host)
    print('port :: ',port)
    print('file_path :: ',file_path)
    if not os.path.exists(file_path):
        print('\n..file not found..\n')
        sys.exit()
    print('\nserver started...')
    Timer(1.0, download_request,args=[host,port]).start()
    Timer(5.0, start_shutdown_server,args=[host,port]).start()
    app.run(host=host,port=port,use_reloader=False)

@app.route('/<file_path>')
def upload_file(file_path):
    try:
        print("\nuploaded file....")
        print(file_path)
        return send_file('/home/einfochips/Desktop/android.tar.gz', as_attachment = True,   cache_timeout = 0)
    except FileNotFoundError as e:
        return "file not found"

if __name__ == '__main__':
    config_param = {}
    config_param["host"] = '127.0.0.1'
    config_param["port"] = 5000
    config_param["file_path"] = '/home/einfochips/Desktop/android.tar.gz'
    start_server(config_param)

我如何从运行中传递参数文件名???

1 个答案:

答案 0 :(得分:1)

您可以从 minTime = '06:30'; maxTime = '07:30';

获取配置
current_app