【发布时间】:2014-12-17 09:42:25
【问题描述】:
我正在尝试通过向我的网络服务器发送“PUT”请求在我的网站上获取我的注册表单。最初我的代码如下所示。
我的 HTML 表单:
<form data-ng-submit="submit()" ng-controller="registrationController">
Please enter your device key
<input type="text" ng-model="text" name="text">
<input type="submit" id="submit" value="Submit">
</form>
我的 Javascript:
homeApp.controller('registrationController', function($scope, $http) {
$scope.submit = function() {
if ($scope.text) {
$http({
method: 'PUT',
url: '/api/v1/device_registration/2345',
data: '',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
$scope.text = 'changeTextTest';
};
};
});
在提交表单时,我可以看到文本更改为“changeTextTest”,但是在终端的输出中(来自 ./manage.py runserver)我可以看到输出状态为 403
"PUT /api/v1/device_registration/2345 HTTP/1.1" 403 58
我认为这是因为我没有发送 CSRF 令牌,所以我将 $cookies 添加到函数范围。
homeApp.controller('registrationController', function($scope, $http, $cookies) {
现在提交后我得到
"GET /app/?text=randomInputText HTTP/1.1" 200 2881
我的浏览器中的 URL 更改为
http://127.0.0.1:8000/app/?text=randomInputText
这里出了什么问题?
【问题讨论】:
标签: django angularjs django-rest-framework