通过Flask(Python)在两个HTML页面之间传递值

3
我的Web应用目前有3个页面。在第一个页面上,我获得了用户的输入并将其传递给了我的view.py文件,并计算了一些我需要用于第二个页面的变量。我想将存在于第二个页面中的变量传递到第三个页面,但是不知道如何实现。您有什么建议可以修改第二个页面的HTML以实现此目的吗?
到目前为止,我通过在view.py中将我的变量设为全局变量来解决这个问题。这似乎有效,但不是长期可行的解决方案。
谢谢!
existing variables: thePrediction, theData

第二页的HTML代码如下:
        <div class = "caption-full">
              <h3>Currently, I have a {{thePercentage}} chance of getting adopted.</h3>
            {% if thePrediction[1] + thePrediction[2] >0%}
                <form action="/third_page" method="GET">
                    <button class="btn btn-large btn-info" >Go to third page</button>
                </form>

            {% endif %}
        </div>
1个回答

2

我想我弄明白了:

<div class = "caption-full">
                  <h3>Currently, I have a {{thePercentage}} chance of getting adopted.</h3>
                {% if thePrediction[1] + thePrediction[2] >0%}

                    <form action="/third_page" method="GET">
                        <input type="hidden" name="alignment" value="{{thePassedValue}}" />
                        <button class="btn btn-large btn-info" >Go to third page</button>

                    </form>

                {% endif %}
            </div>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接