如何将用户重定向到返回的URL python

用户名

因此,我测试了paypal rest sdk,并使用python作为我的cgi语言(我也知道2007)使用im,无论如何我遇到了一个障碍,因为我无法让它重定向到返回的URL页面。

我已经尝试了打印Location方法。它对我没有用。

# Create Payment Using PayPal Sample
# This sample code demonstrates how you can process a
# PayPal Account based Payment.
# API used: /v1/payments/payment
from paypalrestsdk import Payment
import logging

logging.basicConfig(level=logging.INFO)

# Payment
# A Payment Resource; create one using
# the above types and intent as 'sale'
payment = Payment({
"intent": "sale",

# Payer
# A resource representing a Payer that funds a payment
# Payment Method as 'paypal'
"payer": {
    "payment_method": "paypal"},

# Redirect URLs
"redirect_urls": {
    "return_url": "http://localhost:3000/payment/execute",
    "cancel_url": "http://localhost:3000/"},

# Transaction
# A transaction defines the contract of a
# payment - what is the payment for and who
# is fulfilling it.
"transactions": [{

    # ItemList
    "item_list": {
        "items": [{
            "name": "item",
            "sku": "item",
            "price": "5.00",
            "currency": "USD",
            "quantity": 1}]},

    # Amount
    # Let's you specify a payment amount.
    "amount": {
        "total": "5.00",
        "currency": "USD"},
    "description": "This is the payment transaction description."}]})

 # Create Payment and return status
 if payment.create():
 print("Payment[%s] created successfully" % (payment.id))
  # Redirect the user to given approval url
for link in payment.links:
    if link.method == "REDIRECT":
        # Convert to str to avoid google appengine unicode issue
        # https://github.com/paypal/rest-api-sdk-python/pull/58
        redirect_url = str(link.href)
        print("Redirect for approval: %s" % (redirect_url))
else:
    print("Error while creating payment:")
    print(payment.error)

因此,如果您无论如何要在用户浏览器上抛出301或302,那对我真的很有帮助。谢谢你。

用户名

我有点自己解决了。通过将其添加到代码中

print 'Content-Type: text/html'
print 'Location: %s' % redirectURL
print # HTTP says you have to have a blank line between headers and content
print '<html>'
print '  <head>'
print '    <meta http-equiv="refresh" content="0;url=%s" />' %redirectURL
print '    <title>You are going to be redirected</title>'
print '  </head>' 
print '  <body>'
print '    Redirecting... <a href="%s">Click here if you are not redirected</a>' % redirectURL
print '  </body>'
print '</html>'

知道脚本会像超级按钮一样重定向页面。谢谢

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

仅在成功登录(Flask Python App)后,如何将用户重定向到所需的html页面?

如何将用户重定向到当前 url

如何使用Python发出URL请求并返回重定向到的URL?

如何将用户重定向到其他页面?

如何将用户重定向到子域?

如何将python代码的输出重定向到文件

密码确认后如何将用户重定向到URL?

如何将用户重定向到ASP.net Core 1.1 MVC中的新URL

将用户重定向到新的URL

使用React和Typescript完成某些请求后,如何将用户重定向到url“ / home”?

如果用户已经登录,如何将用户重定向到其主页?

注册用户后如何将用户导航(重定向)到页面 - React

如何将用户从控制器重定向到另一个域

如何将用户从 django rest 框架中的中间件重定向到登录页面?

如何将用户重定向到单击编辑按钮的上一页

创建新帖子后如何将用户重定向到新创建的帖子

我们如何将用户重定向到 Django 中的指定管理员?

在 Django 中创建博客后如何将用户重定向到博客

如何将用户号码重定向到电话应用程序颤振

填写登录表单后如何将用户重定向到/ creatPost?

如何将用户从浏览器重定向到iOS中的应用程序?

CodeIgniter-登录后如何将用户重定向到先前尝试的路由

如何将用户重定向到MVC中的登录页面

如何将用户请求重定向到Kubernetes中的另一个部署?

注册失败后如何将用户重定向到特定页面?

登录/注册后如何将用户重定向到特定路由?

如何将用户重定向到通知页面上的单击

如果出现重复输入错误,如何将用户重定向到其他页面?

Symfony-如何将用户重定向到登录后访问的上一页?