Python烧瓶获取和发布的序列 [英] Python Flask Sequence of gets and post

查看:170
本文介绍了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');


$ b $ p
$ b $ p $ < / p> html>
< head>< title> Post< / title>< / head>
< body>
< h1> Hello {{request.form ['username' ]}}

get.html:

 < html> 
< head>< title> Post< / title>< / head>
< body>
< form action =/>
名称:< br>< input type =textname =username>< br> ;



Hi im working with python and flask

im trying to make a page that server takes you to page 1

then you send information to the server

then takes you to page 2.

then you send information

and it takes you to page 3.

How whould i do that?

Here is some sample code that i attempted not sure if its remotely close

    @app.route('/',methods=['GET', 'POST'])
def hello():
    if 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');

解决方案

This sort of logic should be handled within the template itself, or should be split among multiple pages.

Multiple page example:

@app.route('/1',methods=['GET', 'POST'])
def one():
    if request.method == 'GET':
        return render_template('SelectOption.html');
    elif request.method == 'POST':
        option = request.form['option'];

@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")

Split template example:

@app.route('/', methods=['GET', 'POST']
def root():
    if request.method == 'POST':
        return render_template('post.html');
    return render_template('get.html');

post.html:

<html>
<head><title>Post</title></head>
<body>
    <h1>Hello {{ request.form['username'] }}</h1>
</body>

get.html:

<html>
<head><title>Post</title></head>
<body>
    <form action="/">
    Name:<br> <input type="text" name="username"><br>
    <input type="submit" value="Submit">
    </form>
</body>

这篇关于Python烧瓶获取和发布的序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆