简体   繁体   中英

passing variables to a template on a redirect in python

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

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')

最简单的方法是使用HTML表单,提交表单的POST请求应包括提交的值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM