python - PUT method not working in django-tastypie? -
i new django-tastypie. here api.py code,
from tastypie.resources import modelresource .models import listmodel class listmodelresource(modelresource): def determine_format(self, request): return 'application/json' class meta: allowed_methods = ['get','put'] queryset = listmodel.objects.all()
here using 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 test"}
here using curl put:
curl --dump-header - -h "content-type: application/json" '{"completed": false, "id": 1, "resource_uri": "/api/v1/listmodel/1/", "title": "this 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
why getting 401 ?.
according tastypie tutorial:
... if try sending post/put/delete resource, find getting “401 unauthorized” errors. safety, tastypie ships authorization class (“what allowed do”) set readonlyauthorization. makes safe expose on web, prevents doing post/put/delete. ..
you can enable using tastypie.authorization.authorization
:
from tastypie.authorization import authorization tastypie.resources import modelresource .models import listmodel class listmodelresource(modelresource): def determine_format(self, request): return 'application/json' class meta: allowed_methods = ['get','put'] queryset = listmodel.objects.all() authorization= authorization() # <---
warning
this great testing in development very insecure. should never put resource out on internet. please spend time looking @ authentication/authorization classes available in tastypie.
Comments
Post a Comment