Python烧瓶获取和发布的序列 [英] Python Flask Sequence of gets and post
本文介绍了Python烧瓶获取和发布的序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我正在使用Python和烧瓶
我试图做一个页面,服务器把你带到第1页
然后你发送信息到服务器
然后把你带到第2页。
然后你发送信息然后把你带到第3页。
我该怎么做?
下面是一些示例代码,我试图不确定它是否远程关闭
<$ c $ b $ def hello():$ b $如果request.method =='GET':
return render_template('SelectOption.html');
elif request.method =='POST':
option = request.form ['option'];
if option ==1:
return render_template('Option1.html',option = option)
if request.method =='POST':
return render_template 'charts.html');
elif option ==2:
return render_template(Charts.html)
if request.method =='POST':
return render_template('charts.html );
解决方案
这种逻辑应该在模板本身内处理,或者应该分成多个页面。
多页面示例:
<$ c $如果request.method =='GET':
$ def $($)
如果request.method =='GET':
return render_template('SelectOption.html');
elif request.method =='POST':
option = request.form ['option'];
$ b @ app.route('/ 2',methods = ['GET','POST'])
def two():
if request.method ==' POST':
return render_template('charts.html');
return render_template('Option1.html',option = option)
@ app.route('/ 3',methods = ['GET','POST'])
def three():
if request.method =='POST':
return render_template('charts.html');
return render_template(Charts.html)
拆分模板示例:
$ b $
@ app.route('/',methods = ['GET','POST']
def root():
if request.method =='POST':
return render_template('post.html');
return render_template('get.html');
$ c $
$ b $ p
$ b $ p $ < / p> html>
< head>< title> Post< / title>< / head>
< body>
< h1> Hello {{request.form ['username' ]}}