小编Aak*_*tel的帖子

Angular JS和Flask RESTful API

我目前正在开发一个站点,该站点使用Angular JS作为前端框架,使用Flask作为RESTful API.我正在使用vagrant来托管我的应用所在的LAMP服务器.API使用curl进行测试,它完全按照我的要求运行.

运行应用程序时出现以下错误:

`*GET http://localhost:5000/choreographer/api/v1.0/choreographers net::ERR_CONNECTION_REFUSED
(anonymous function) @ angular.js:10722
sendReq              @ angular.js:10515
serverRequest        @ angular.js:10222
processQueue         @ angular.js:14745
(anonymous function) @ angular.js:14761
Scope.$eval          @ angular.js:15989
Scope.$digest        @ angular.js:15800
Scope.$apply         @ angular.js:16097
(anonymous function) @ angular.js:12226
eventHandler @ angular.js:3298*`
Run Code Online (Sandbox Code Playgroud)

我原本以为这可能是一个CORS问题,所以我尝试使用$http.jsonp().这产生了同样的错误.我知道有些东西阻碍了我访问API的能力,但我不知道是什么或如何解决它.

我的AngularJS模块如下:

angular.module('myApp.choreographer', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/choreographer', {
    templateUrl: 'choreographer/choreographer.html',
    controller: 'choreographerCtrl'
    });
}])
.factory('choreographerService', function($resource) {
    return $resource('http://localhost:5000/choreographer/api/v1.0/choreographers');
})
.controller('choreographerCtrl', function($scope, choreographerService) {
    var choreographers = choreographerService.query(function() {
        console.log(choreographers);
        }); //query() returns all the entries
    }); …
Run Code Online (Sandbox Code Playgroud)

python cors angularjs flask-restful

5
推荐指数
0
解决办法
1083
查看次数

标签 统计

angularjs ×1

cors ×1

flask-restful ×1

python ×1