【问题标题】:Python Flask Sequence of gets and postPython Flask 获取和发布的序列
【发布时间】:2016-02-17 03:30:04
【问题描述】:

您好,我正在使用 python 和烧瓶

我正在尝试制作一个页面,服务器会将您带到第 1 页

然后你将信息发送到服务器

然后将您带到第 2 页。

然后你发送信息

它会将您带到第 3 页。

我应该怎么做?

这是一些示例代码,我尝试不确定它是否远程关闭

    @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');

【问题讨论】:

    标签: python post flask get sequence


    【解决方案1】:

    这种逻辑应该在模板本身内处理,或者应该在多个页面中拆分。

    多页示例:

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

    拆分模板示例:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-04
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      • 2017-09-09
      • 2021-05-21
      相关资源
      最近更新 更多