passing variables to a template on a redirect in p

2019-04-27 12:07发布

I am relatively new to Python so please excuse any naive questions.

I have a home page with 2 inputs, one for a "product" and one for an "email." When a user clicks submit they should be sent to "/success" where it will say: You have requested "product" You will be notified at "email"

I am trying to figure out the best way to pass the "product" and "email" values through the redirect into my "/success" template. I am using webapp2 framework and jinja within Google App Enginge.

Thanks

2条回答
成全新的幸福
2楼-- · 2019-04-27 12:23

When you do your redirect, include your email and product variables in the redirect. In Google appp engine, using webapp2, your current redirect probably looks like:

self.redirect('/sucess')

Instead, you can add the variables in the URL as follows:

self.redirect('/success?email=' + email + '&product=' + product)

The above URL would look like '/success?email=this@email.com&product=this_product' after concatenating the values.

The handler for /success could then get those values with:

email = self.request.get('email')
product = self.request.get('product')
查看更多
Luminary・发光体
3楼-- · 2019-04-27 12:35

The easiest way is to use HTML forms, the POST request for submitting the form should include the values on the submit.

查看更多
登录 后发表回答