将变量传递给python中的重定向模板 [英] passing variables to a template on a redirect in python

查看:104
本文介绍了将变量传递给python中的重定向模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Python比较陌生,所以请原谅任何天真的问题。

我有一个主页有2个输入,一个用于产品,另一个用于电子邮件。当用户点击提交时,他们应该被发送到/成功,它会说:
您已经要求产品
您会收到电子邮件通知



我试图找出通过重定向到我的/ success模板来传递产品和电子邮件值的最佳方法。我在Google App Enginge中使用了webapp2框架和jinja。
$ b

谢谢

当您进行重定向时,请将您的电子邮件和产品变量包含在重定向中。在Google appp引擎中,使用webapp2,您当前的重定向可能如下所示:

  self.redirect('/ sucess')

相反,您可以按如下方式在URL中添加变量:

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

在连接值后,上述网址看起来像是/success?email=this@email.com&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 '/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')

这篇关于将变量传递给python中的重定向模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆