I´m building a little web application using python 2.7 and flask (my first one).
I´m trying to include three HTML forms in one flask view to have all three of the forms on one webpage:
While I got it working, when using a separate view for each of the three steps, I somehow can´t get it done when trying to include all three steps in one view. Does anyone know what I am doing wrong?
Here´s my code so far. The HTML-code is included in the python script. Working with templates didn´t help me either. The HTML page is working, but the buttons don´t perform any action.
...
@app.route('/PAM', methods=['GET', 'POST'])
def start_PAM():
if request.method == 'POST':
if "Upload" in request.form.values():
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
print "File upload complete !!"
return redirect('/PAM')
elif "Start PAM" in request.form.values():
import os
os.system("D:\Python_Test\PAM\PAM_1st_Try.py")
print "PAM Process Finished!!"
return redirect('/PAM')
elif "Download" in request.form.values():
filename = "FILE.XML"
return redirect(url_for('download_file', filename=filename))
return '''
<!doctype html>
<title>Start PAM Process</title>
<h1>XML Upload</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
<p><h1>Start the PAM Process</h1>
<form name='Start PAM' method='POST'>
<p><input type="submit" value="PAM" class="submitButton"/>
</form>
<p><h1>Download Result</h1>
<form name='Download' method='POST'>
<p><input type="submit" value="Download" class="submitButton"/>
</form>
'''
@app.route("/downloads/<filename>")
def download_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename, as_attachment=True)
app.debug = True
if __name__ == '__main__':
app.run()
I think the step you're missing is to assign an action to the forms. At the moment the HTML doesn't know what to do with the form?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.