2015-07-19 168 views
1

我很webb开发新手。我试图学习如何在谷歌应用程序引擎上开发Web服务,但是使用模板jinja2,谷歌教程摘要,我希望页面在客户端构建并使用angularjs。我想就如何组织项目yaml提供一些建议,如何从app.py提供javascript,我会赞赏它。谷歌应用程序引擎蟒蛇

Thanx。

+0

有什么问题? Javascript只是一个静态文件。 – marcadian

回答

0

您可以组织项目就像任何其他angularjs项目,您可以了解更多关于在以下链接组织angularjs项目:

AngularJS application file structure

例如:

  • project_directory
    • app
      • 资产(图片,字体等)
      • 脚本(控制器,指令,服务,插件等)
      • 样式(CSS等)
      • 测试(单元)
      • 意见(HTML等)
      • 的index.html
    • app.py
    • 的app.yaml

在你的app.yaml添加处理程序:

- url:/
    static_files: app/index.html 

- url: /.* 
    script: app.application 

要想从德app.py数据,你需要做的HTTP请求到Python类地址。例如:

在app.py:

# [START UserLogout] 
class UserLogout(webapp2.RequestHandler): 
    def get(self): 
     url_logout = users.create_logout_url('/') 
     self.response.out.write(url_logout) 
# [END UserLogout] 

和:

application = webapp2.WSGIApplication([ 
    ('/SampleClass', SampleClass), 
    ('/UserLogout', UserLogout), 
    (decorator.callback_path, decorator.callback_handler()) 
], debug=True) 

在这个例子中,提出请求,以获得注销URL并将用户重定向:

function logoutCtrl($http, $scope) { 
     $scope.logoutUrlClick = function() { 
     $http.get('UserLogout'). 
     success(function(data_logout, status, headers, config) { 
      // when the response is available 
      window.location= data_logout; 
     }). 
     error(function(data_logout, status, headers, config) { 
      // when server returns response with an error status. 
      // some error notification 
     }); 
     }; 
}; 

要查看更多关于$ http方法的信息,请参阅:

https://docs.angularjs.org/api/ng/service/$http