问题描述
我对Python比较陌生,所以请原谅任何天真的问题。
我有一个主页有2个输入,一个用于产品,另一个用于电子邮件。当用户点击提交时,他们应该被发送到/成功,它会说:
您已经要求产品
您会收到电子邮件通知
我试图找出通过重定向到我的/ success模板来传递产品和电子邮件值的最佳方法。我在Google App Enginge中使用了webapp2框架和jinja。
$ b
谢谢
当您进行重定向时,请将您的电子邮件和产品变量包含在重定向中。在Google appp引擎中,使用webapp2,您当前的重定向可能如下所示:
self.redirect('/ sucess')
相反,您可以按如下方式在URL中添加变量:
self.redirect('/ success?email ='+ email +'& product ='+ product)
pre>
在连接值后,上述网址看起来像是/[email protected]&product=this_product。
成功的处理程序可以获取这些值:
email = self.request.get('email')
product = self.request.get('product')
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 '/[email protected]&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')
这篇关于将变量传递给python中的重定向模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!