错误405获取方法不被允许

时间:2017-06-18 05:01:14

标签: python angularjs google-app-engine

Angularjs代码

 var app = angular.module('myApp', []);
 app.factory('httpSend', ['$http', '$q', function($http, $q) {
     var app = {};
     app.sendToServer = function(data) {
         $http({
             method: "POST",
             url: '/report',
             data: data,
             headers: {
                 'Content-type': 'application/x-www-form.urlencoded;'
             }
         }).then(function(response) {
             debugger
             var result = data;
         });
     }
     app.getfromServer = function() {
         var def = $q.defer();
         $http.get('/report').then(function(data) {
                 console.log(data);
                 def.resolve(data);
             }),
             function(error) {
                 def.reject("Failed to get albums");
             };
         return def.promise;
     }
     return app;
 }]);
 app.controller('myCtrl', ['$scope', '$http', 'httpSend', '$filter', function($scope, $http, httpSend, $filter) {
     $scope.names = ["ankit patidar", "adhishi ahari", "kritin joshi", "kautilya bharadwaj", "punita ojha", "manvi agarwal", "apeksha purohit", "shipra jain", "mansi nangawat", "praveen soni"];
     $scope.data = [];
     $scope.names.forEach(function(name) {
         $scope.data.push({
             name: name,
             checkin: "",
             checkout: ""
         })
     });
     $scope.login = [];
     $scope.check = function(name, doing) {
         debugger
         name[doing] = new Date();
         name[doing] = $filter('date')(name[doing], 'dd-MM-yyyy hh:mm:ss');
         $scope.login.push(angular.copy(name));
         if (doing == "checkout") {
             var q = JSON.stringify($scope.login);
             httpSend.sendToServer(q);
         }
     }
     $scope.getData = function() {
         httpSend.getfromServer();
     }
 }]);

`

Python代码

 def get(self):
 logging.info('get is triggered')
 obj = CheckIn.query().fetch()
 emp_obj = []
 for x in obj:
     logging.info('I am inside for loop ')
 emp_obj.append({
     'name': x.name,
     'Check_in': x.inDate,
     'check_out': x.outDate
 })
 logging.info('I am inside emp_obj')
 self.response.write(json.dumps(emp_obj))

我需要获取前端视图上存储在ndb数据存储区中的所有数据,这就是为什么我使用http get方法但是错误显示方法不允许。尽管使用查询获取并在python ad触发get方法上显示其响应,为什么会出现错误,控制流中是否存在错误或者我的get方法中缺少某些内容,因为现在我可以发布nd存储数据

1 个答案:

答案 0 :(得分:0)

将您的工厂更改为以下内容。不要使用您用来为控制器逻辑初始化模块的相同变量应用程序。

app.factory('httpSend',['$http', '$q',function($http, $q){
  return {
    'sendToServer': function(data) {
      var def = $q.defer();
        $http({
            method: "POST",
            url: '/report',
            data: data,
            headers: {
                'Content-Type': 'application/json'
            }
        }).then(function(response) {
            debugger
            var result = response.data;
            def.resolve(result );
        });
          return def.promise;
    },
    'getfromServer': function() {
        var def = $q.defer();
        $http.get('/report').then(function(data) {
                console.log(data);
                def.resolve(data);
            }),
            function(error) {
                def.reject("Failed to get albums");
            };
        return def.promise;
    }
}
        }]);