Redirecting after Python Cloud Function

Viewed 1075

My HTML form has

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

with

method="post" target="_blank"

The link sends an email address string to a Google Cloud Function in the Python 3.7 Beta Runtime.

The function performs correctly and interacts with a third party API.

After the function runs it loads a blank page with

OK

as the only content. From here I'd like to redirect back to my website but I can't quit figure out how to do this. Ive tried

  • Placing a urllib.request at the end of my Python function
  • Performing an XMLHttpRequest
  • Changing

    target="_blank"
    

    to

    target="_self"
    

What is the correct way to do this?

1 Answers

Google Cloud Functions uses Flask under the hood to serve your endpoint, so you can just return a redirect at the end:

from flask import redirect

def test(request):
    return redirect('https://google.com')
Related