I recently got some tips on an easy-to-use web framework for a simple project that I'm helping a friend with, and I was asked to use Flask.
Everything is still working - however, I'm trying to figure out how (or, if possible) to read the file on the fly, and pass the contents of the file to the function that I have.
For example, I would like to use something like the following:
HTML side:
<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>
I believe that this is all I need on the actual page using HTML, as this will allow me to get the path to the file that I need, so I hope I can read the specified file.
I'm not sure where to go towards Flask / Python - I'm just looking for a step in the right direction, maybe I read two numbers or letters (in a file) and display them on the same page?
/ 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)
, - , - Flask/Python .
: , Flask, , jQuery, , / ?
.