尝试使用AngularJS进行POST时,即使页面存在,也会收到404错误

时间:2013-10-30 13:08:51

标签: javascript python django http angularjs

POST http://api.link/api/v1/articlerevision 404 (NOT FOUND)

当我尝试通过AngularJS和Django-Tastypie API添加新项时,出现以下错误。如果我在浏览器中打开链接,它会起作用,在我提交表单时下注,但事实并非如此。我已将allowed_methods设置为get, put, post, delete,但这似乎无法解决任何问题。还有什么其他选择?

编辑:

view.tpl.html

<div ng-controller="CreateCtrl">
    <form class="form-horizontal">
        <fieldset>
            <label>
            Title
            <input class="form-control" type="text" ng-model="revision.title" placeholder="Title">
            </label>

            <br />

            <label>
            Description
            <textarea class="form-control" type="text" ng-model="revision.content"></textarea>
            </label>

            <button ng-click="create()">Save</button>
        </fieldset>
    </form>
</div>

var tastypieDataTransformer = function ($http) {
    return $http.defaults.transformResponse.concat([
        function (data, headersGetter) {
            var result = data.objects;
            result.meta = data.meta;
            return result;
        }
    ]);
};

bosApp.factory('Revision', function($resource, $http) {
    return $resource('http://api.link/api/v1/articlerevision/:id/', {
            id: '@is'
        },
        {
            update: {
                method: 'POST',
                params: {"update": true},
                isArray: false
            },
            save: {
                method: 'PUT'
            },
            query: {
                method: 'GET',
                isArray: true,
                transformResponse: tastypieDataTransformer($http)
            },
            create: {
                method: 'POST'
            }
        }
    );
});

var CreateCtrl = function($scope, $location, Revision) {
    $scope.create = function() {
        Revision.create($scope.revision);
    };
};

0 个答案:

没有答案