烧瓶重定向后保存变量

时间:2019-03-13 15:24:48

标签: python flask

在我的Flask脚本中,我从自己的路线中获取了一个变量/ students,然后将其移至/ user。但是,我需要将信息从用户页面本身发布到/ user中,但是每次我将信息发布到/ user中时,它都会丢失从/ students获取的信息,因为我不是从那里发布的。这是我的代码示例。

烧瓶

@app.route('/user', methods = ['POST'])
def user():
    studentSQL = request.form["StudentDB"]

    with sqlite3.connect("twoDadDatabase.db") as con:
        cur = con.cursor()

        cur.execute("SELECT * FROM students WHERE name =? ", (studentSQL,))
        dataTest = cur.fetchall()

        if request.form.get("minusOne", False):
            cur.execute("UPDATE students SET Preparedness = Preparedness - 1 WHERE name =? ", (studentSQL,))
            print("-1 on Preparedness for " + studentSQL)
        if request.form.get("plusOne", False):
            print("+1 on Preparedness for " + studentSQL)

    return render_template("user.html", student=studentSQL, data=dataTest)

HTML

/学生

<form action="{{ url_for('user') }}" method = "POST">
    <input type="submit", name="StudentDB" value={{ row[0] }}>

/用户

<h2>Student Name: {{ student }}</h2>

<form action="{{ url_for('user') }}" method = "POST">
    <input type="submit" name="minusOne" value="-1" style="float: left;"> 
    <input type="submit" name="plusOne" value="+1" style="float: right;">
</form>

0 个答案:

没有答案