2
我有發帖請求的問題。當用戶嘗試提交表單時,下面的代碼失敗,tornado handler.get_argument('login')和handler.get_argument('password')都返回None,而我明確發送這些數據。更有趣的是,當我改變方法從發佈到獲取時,一切正常。如何使它也適用於發佈請求?角度/龍捲風網站中的發佈請求
//angular js
angular.module('playItApp', ['playItControllers', 'playItServices']);
angular.module('playItServices', ['ngResource'])
.factory('users', ['$resource', function($resource){
return $resource('/api/user');
}]);
angular.module('playItControllers', [])
.controller('authentication', ['users', function(users){
this.register = function(){
users.save({'login': this.login, 'password': this.password});
};
}]);
# tornado handler
class User(JsonHandler):
def post(self):
login = self.get_argument('login')
password = self.get_argument('password')
user = self.db.create_user(login, password)
self.set_secure_cookie('user', str(user['id']))
self.write(user)
<div ng-controller="authentication as authentication">
<h2>Registration</h2>
<form>
<input type="text" placeholder="login" ng-model="authentication.login">
<input type="password" placeholder="password" ng-model="authentication.password">
<button ng-click="authentication.register()">Register</button>
</form>
</div>