在“ while”(烧瓶)中使用“ request.method”语句

时间:2019-11-25 15:27:08

标签: python flask logic

我在通过条件语句开发循环时遇到问题。系统无限次地要求我提供数据,而不考虑“ x”值。我想重复de interface“ x”次,然后返回称为“ EF”的总结果。这是代码:

from flask import Flask, request, session

app = Flask(__name__) #create the Flask app
app.secret_key = "hello"

@app.route('/begin', methods=['GET', 'POST'])
def form():
    x = 2
    i = 1
    EF = int()
    EFT = int()
    while i <= x:

            if request.method == 'POST':
                y1 = request.form['y1']
                session ['y1'] = y1

                EF = EF + int(y1)
                i += 1
                session ['EF'] = EF


            return '''<form method="POST">

            Input y1:        <input type="text" name="y1"><br>

                        <input type="submit" value="Ingresar"><br>

                        <input type="reset" value="Borrar todo"><br>

                        <input type="button" onclick="history.back()" name="back" value="back"><br>

                    </form>'''



    return '''The value is: '''+str(EF)



if __name__ == '__main__':
  app.config['SESSION_TYPE'] = 'filesystem'
  app.run(debug=True, port=5000)

0 个答案:

没有答案