0

Initially the user is presented with a form which he inputs some values and clicks Submit. Once Submit is clicked the class One is called which renders a jinja2 template with the results.

class One(webapp2.RequestHandler):
  def post(self):
    # It gets the user's input from
    # an HTML form
    area = self.request.get('area')

    # It then passes area in a
    # different class (CalculateArea)
    # for some calculations

    calculations = CalculateArea()
    results = calculations.distance(area)

    values = {
      'results': results
    }

    template = JINJA_ENVIRONMENT.get_template('results.html')
    self.response.write(template.render(values))

On the rendered page there is a new button which when clicked calls class Two.

class Two():
  def get(self):
    # Here I want to use area and results from class One
    distance = area
    new = results

What I'm trying to do is to use variables area and results in Class Two.

kalpetros
  • 983
  • 3
  • 15
  • 35

2 Answers2

2

There are multiple ways to get this done.

  1. Save to datastore and retrieve when needed. But then , frequent requests on the Two page might make the system less performant.

  2. Save the values you require to session. Check out here

    Hope it helps.

Community
  • 1
  • 1
formatkaka
  • 1,278
  • 3
  • 13
  • 27
0

2 options that I can think of

1) Since you're already passing results back to your page, you can also pass 'area' back to the page and then the submit button when clicked will pass both results and area back to Class Two

2) Use memcache -

from google.appengine.api import memcache

In Class One(), add the following code (just after you get the results)

memcache.add(area, results)

In Class Two(), add the following code. Note that it means you have to pass area again when calling Class Two

memcache.get(area)
N.P
  • 245
  • 1
  • 12