Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing values from one html page to another via Flask (Python)

My web app currently has 3 pages. I obtained a user input on the first page, which I passed to my view.py, and calculated some variables I needed for my 2nd page. I want to pass the variables that exist in my 2nd page to the third page, but don't know how to go about it. Any suggestions on how to modify the html for the 2nd page to achieve this?

So far, I'm solving this problem by making my variables global in view.py. This seems to work but doesn't seem to be a viable long-term solution.

Thanks!

existing variables: thePrediction, theData

The html for the 2nd page:

        <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>
like image 909
monkeybiz7 Avatar asked Apr 20 '26 22:04

monkeybiz7


1 Answers

I think I figured it out:

<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>
like image 97
monkeybiz7 Avatar answered Apr 22 '26 13:04

monkeybiz7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!