我最近收到了一些关于易于使用的web框架的问题的建议,用于一个简单的项目,我正在帮助一个朋友,并建议使用Flask。在Flask中动态分析文件
到目前为止,一切都一直在努力 - 但我试图弄清楚如何(或者如果有可能)在飞行中读取文件,并将文件内容传递到我拥有的函数中。
举例来说,我会想使用类似以下内容:
HTML端:
<form action="process_file" method=post enctype=multipart/form-data>
<input type='file' name='file'>
<input type='submit' value="Upload and Process Selected File">
</form>
我想这是所有我需要用HTML实际的页面上,因为这会让我得到我需要的文件的路径,所以希望我能够读取所述文件。
我不确定在瓶子/ Python那边去哪里 - 我只是寻找正确方向的一步,或许用两个数字或字母(在文件中)读取并输出它们同一页?
瓶/ Python端:
@app.route('/process_file', methods=['GET', 'POST'])
def process_file():
if request.method == 'POST':
file = request.files.get('file')
if file:
"Read file and parse the values into an array?"
"Pass arguments to a Processing function and outputs result into x)"
return render_template('index.html',answer = x)
else:
return render_template('index.html',error=1)
我不知道如果我在正确的方向我当家 - 我只是以为有人用瓶/ Python的经验可能会导致我在那里。
编辑:我还注意到,Flask似乎与jQuery很好地合作,将它们结合起来使处理/文件解析更简单吗?
谢谢大家。
谢谢汤姆! - 我只是想从文件输入中获得文件(或文件路径),我可以说如何逐行读取数组或其他东西。我会看看你提供的链接 – 2011-02-09 21:49:35