I want to run a client-side file dialog GUI so that the user can choose a file to process with python (example). My code, which fundamentally works fine, is here:
from flask import Flask, url_for, request
app = Flask(__name__)
@app.route('/data')
def gui_test():
import Tkinter, tkFileDialog
root = Tkinter.Tk()
root.withdraw()
filepath = tkFileDialog.askopenfilename()
with open(filepath,'rb') as tt:
lines = tt.readlines()
return 'You are reading ' + filepath + '<p>Top 10 lines for proof of concept<p>'+'<br>'.join(lines[0:10])
if __name__ == '__main__':
app.run()
Everything works fine, except that the GUI opens on the machine running this REST code, and not on in the client's user account.
The user should go with the browser to http://127.0.0.1:5000/data and then should see the file dialog:
Details: Windows Server 2012 R2, Flask 0.10.1, Python 2.7
If I'm taking the wrong approach, I'd appreciate suggestions for other directions. There may be something flawed in the idea, because of browsers not sharing the full path (javascript example).