2
我在AngularJS中遇到了我的http POST请求问题。我得到的错误是:
POST http://localhost:8080/ 403 (Forbidden). 'rating-add' is a named url
所以我不知道为什么它不允许这样。这是模板:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http){
$scope.ratings = [];
var data = $scope.myForm = {beer_name:'', score:'', notes:'', brewer:''};
$scope.buttonClick = false;
$scope.is_clicked = function() {
$scope.buttonClick=true;
console.log($scope.buttonClick)
}
$scope.submit_to_form = function() {
$http({
method: 'POST'
url: 'rating-add'
data: data
});
}
})
</script>
而urls.py:
from django.conf.urls import url
from django.contrib import admin
from ratings.views import home, RatingCreate, delete, edit
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', RatingCreate.as_view(), name='rating-home'),
url(r'rating/add/$', RatingCreate.as_view(), name='rating-add'),
url(r'rating/delete/(?P<row_id>[0-9]+)/$', delete , name='rating-delete'),
url(r'rating/edit/(?P<row_id>[0-9]+)/$', edit , name='rating-edit'),
]
这不起作用,因为'rating-add'是一个指定的url。 所以/ rating-add与任何urlconf都不匹配。 但即使当我尝试'/评价/添加/'我仍然得到相同的错误。 – user3251349
你有没有尝试删除尾部的斜线?或尝试类似评分/添加/ 1 – atefth
感谢您的帮助。我如何打印我的路线? – user3251349