Skip to main content
 首页 » 编程设计

python之在 Python Cloud Function 之后重定向

2024年12月31日6JustinYoung

我的 HTML 表单有

action="https://us-central1-PROJECT_ID.cloudfunctions.net/FUNCTION_ID" 

与

method="post" target="_blank" 

该链接将电子邮件地址字符串发送到 Python 3.7 Beta 运行时中的 Google Cloud Functions。

函数正确执行并与第三方 API 交互。

函数运行后加载一个空白页面

OK 

作为唯一的内容。我想从这里重定向回我的网站,但我无法停止弄清楚如何做到这一点。 我试过了

  • 在我的 Python 函数末尾放置一个 urllib.request
  • 执行 XMLHttpRequest
  • 改变

    target="_blank" 
    

    到

    target="_self" 
    

正确的做法是什么?

请您参考如下方法:

Google Cloud Functions 使用 Flask在引擎盖下为您的端点提供服务,因此您只需返回 redirect最后:

from flask import redirect 
 
def test(request): 
    return redirect('https://google.com')