我有这个:
处理程序.py
class ChatHandler(BaseHandler):
model = ChatMsg
allowed_methods = ('POST','GET')
def create(self, request, text):
message = ChatMsg(user = request.user, text = request.POST['text'])
message.save()
return message
模板.html
...
<script type="text/javascript">
$(function(){
$('.chat-btn').click(function(){
$.ajax({
url: '/api/post/',
type: 'POST',
dataType: 'application/json',
data: {text: $('.chat').val()}
})
})
})
</script>
...
api/urls.py
chat_handler = Resource(ChatHandler, authentication=HttpBasicAuthentication)
urlpatterns = patterns('',
....
url(r'^chat/$', chat_handler, {'emitter_format': 'json'}),
)
为什么,但是 ChatHandler 中允许使用 POST 方法?GET 方法有效。是错误还是我的代码错误?