Issue
I Have created a flask app which need to upload files to server and also need to take login detail on same html form .
I am able to upload file to destination folder , but credential part is not getting fetched/submit to form and unable to get this in flask app for further processing .
i need to do some operation on this file based on user credentials ( i know credential are plain text )
Html form :-
<form action="/import" enctype="multipart/form-data" method="post">
<p>User name <input name="username" type="text" /></p>
<p>User password: <input name="psw" type="password" /></p>
<p><input name="file" type="file" /> <input type="submit" value="Submit" /></p>
</form>
Flask Application code :-
from flask import Flask, render_template, request
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/import')
def import_form():
return render_template('import.html')
@app.route('/import', methods = ['GET', 'POST'])
def import_form():
if request.method == 'POST':
username = request.args.get('username')
psw = request.args.get('psw')
psw = str(psw)
username=str(username)
f = request.files['file']
f.save(secure_filename(f.filename))
fname = f.filename
cmd = ('sh myscript.sh -u '+username+' -p '+psw+' -src '+fname) # command to pass parameter as user name password and file name in directory
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
return out
if __name__ == '__main__':
app.run(debug = True)
output of this come as below ( user name and password value come as blank/none )
sh myscript.sh -u none -p none -src xyz.file
I want to get user name password and file upload on same page then process this request under a shell script t o return output of it
Solution
Got solution for this issue by one of my colleagues help
need to use as below to get argument enter on screen form .
username = request.form['username']
psw = reques.form['psw']
Answered By - Chandramani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.