将参数传递给其他Python文件

时间:2014-08-04 17:33:25

标签: python file parameters flask global-variables

我正在使用Flask和Python。对于一条路线,我正在做以下

@app.route('/volumes/<volumeid>')
def volumeSpecific(volumeid):
   if volumeid not in volumesList:
    abort(404)
else:
    import retrieveVolumes
    return render_template('index.html')

问题是,在我的retrieveVolumes文件中,我需要特定的volumeid参数。

retrieveVolumes文件中,这是我使用它的地方

current_snapshots = conn.get_all_snapshots(filters={'volume-id': volumeId})

我尝试为参数volumeid创建一个全局变量,但这不起作用。

如何将参数传递给其他文件?

1 个答案:

答案 0 :(得分:0)

模块不能用作函数。至少在retrieveVolumes模块中添加main函数,然后您可以使用main(volumeId=volumeId)或类似函数调用它。