How to pass data from python backend to JavaScript client on Google App Engine?

瀏覽次數:399 次
跳到第一則未讀訊息

Ray Wong

未讀,
2019年8月12日 下午2:22:092019/8/12
收件者:Google App Engine
At present I deploy my gae project on appscale. I want to  pass data to html page. I know a simple way is to use Google JavaScript Library. But for some reason, the https://apis.google.com/js/client.js is blocked and I can't use this library.  So I want to ask are there other ways to get  backend data(written in python) for javascript page. Thanks!  

Tiago (Google Cloud Platform Support)

未讀,
2019年8月13日 晚上9:50:142019/8/13
收件者:Google App Engine
Thank you for using Google Groups!

Passing data between a backend and frontend service differs depending on the language and/or framework you are using. Should you be adopting a RESTful backend architecture in Python such as Flask, you can define a route handler, hit it with a GET request using the Fetch API from JavaScript, and then have the data returned using the response object in your 'main.py' file.

You can follow this tutorial on how to write route handlers using Flask that you can then hit using the Fetch API from JavaScript, and have data returned from the backend service to the frontend service. 

Furthermore, you can use the GCP Flask tutorial to get you started.

Finally, these types of questions are better addressed on StackOverflow where you have access to a large community of enthusiasts and experts to share ideas with and get support from. Please make sure to include all relevant details and error messages which would help the community troubleshoot.

Ray Wong

未讀,
2019年8月15日 凌晨3:35:122019/8/15
收件者:Google App Engine
Thanks for your reply! The previous way to get data using AngularJS $http. Some code is like this:
dashboard_app.factory('DashboardDataFetching', function($location, $http) {
  return {
    'GetArticleProgress': function(article_urlsafe, call_back) {
      $http.post("/_api/get_progress", JSON.stringify({
        'article_urlsafe': article_urlsafe
      })).then(call_back);
    },
  }
});

The key issue is that without using JavaScript client library(https://apis.google.com/js/client.js), I can't get the call_back. That is to say, I can't access the url successfully without it while others have no problem. Is there any way to slove this please?  

Nicolas (Google Cloud Platform Support)

未讀,
2019年8月15日 下午5:05:302019/8/15
收件者:Google App Engine

Hi Ray,

As mentioned by Tiago, you will be better assisted on StackOverflow as Google Groups are more oriented towards general opinions, trends, and issues of general nature touching App Engine.
回覆所有人
回覆作者
轉寄
0 則新訊息