【发布时间】:2015-04-27 07:33:47
【问题描述】:
我在发出发帖请求时遇到问题。当用户尝试提交表单时,以下代码失败,tornado handler.get_argument('login') 和 handler.get_argument('password') 都返回 None,而我清楚地发送了这些数据。更有趣的是,当我将方法从 post 更改为 get 时,一切正常。如何使其也适用于发布请求?
//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>
【问题讨论】: