【发布时间】:2017-04-18 15:28:24
【问题描述】:
我试图在 django 中使用 angular $http.post 方法发布数据,我想知道如何在我的 django 视图中访问该参数值:-
这是我的 controller.js
var nameSpace = angular.module("ajax", ['ngCookies']);
nameSpace.controller("MyFormCtrl", ['$scope', '$http', '$cookies',
function ($scope, $http, $cookies) {
$http.defaults.headers.post['Content-Type'] = 'application/json';
// To send the csrf code.
$http.defaults.headers.post['X-CSRFToken'] = $cookies.get('csrftoken');
// This function is called when the form is submitted.
$scope.submit = function ($event) {
// Prevent page reload.
$event.preventDefault();
// Send the data.
var in_data = jQuery.param({'content': $scope.card.content,'csrfmiddlewaretoken': $cookies.csrftoken});
$http.post('add_card/', in_data)
.then(function(json) {
// Reset the form in case of success.
console.log(json.data);
$scope.card = angular.copy({});
});
}
}]);
这是我试图在我的视图函数中访问的内容:-
card.content =request.POST.get('content')
card 是我模型的对象,但我收到 NameError: name 'content' is not defined,请帮帮我!
【问题讨论】:
标签: javascript angularjs django django-views