我是 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()
在这里,我使用 CURL 进行 GET:
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"}
在这里,我使用 CURL 进行 PUT:
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 ?