私はdjango-tastypieが初めてです。ここに私の api.py コード、
from tastypie.resources import ModelResource
from .models import ListModel
class ListModelResource(ModelResource):
def determine_format(self, request):
return 'application/json'
class Meta:
allowed_methods = ['get','put']
queryset = ListModel.objects.all()
ここでは、GET に CURL を使用しています。
curl http://127.0.0.1:8000/api/v1/listmodel/1/
OUT: {"completed": false, "id": 1, "resource_uri": "/api/v1/listmodel/1/", "title": "This is test"}
ここでは、PUT に CURL を使用しています。
curl --dump-header - -H "Content-Type: application/json" '{"completed": false, "id": 1, "resource_uri": "/api/v1/listmodel/1/", "title": "This is test"}' http://127.0.0.1:8000/api/v1/listmodel/1/
HTTP/1.0 401 UNAUTHORIZED
Date: Wed, 04 Sep 2013 08:12:53 GMT
Server: WSGIServer/0.1 Python/2.7.2+
Content-Type: text/html; charset=utf-8
なぜ私は401を取得していますか?.