[英]How to include more than one HTML-form in a FLASK view?
I´m building a little web application using python 2.7 and flask (my first one). 我正在使用python 2.7和flask (我的第一个)构建一个小的Web应用程序。
I´m trying to include three HTML forms in one flask view to have all three of the forms on one webpage: 我试图在一个烧瓶视图中包含三个HTML表单 ,以将所有三个表单都放在一个网页上:
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.
HTML代码包含在python脚本中。 Working with templates didn´t help me either.
使用模板也无济于事。 The HTML page is working, but the buttons don´t perform any action.
HTML页面正在运行,但是按钮不执行任何操作。
...
@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?
目前,HTML不知道如何处理表单?
http://www.w3schools.com/tags/att_form_action.asp http://www.w3schools.com/tags/att_form_action.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.