[Answered ]-PUT method not working in django-tastypie?

2đź‘Ť

âś…

According to tastypie tutorial:

… if you try sending a POST/PUT/DELETE to the resource, you find
yourself getting “401 Unauthorized” errors. For safety, Tastypie ships
with the authorization class (“what are you allowed to do”) set to
ReadOnlyAuthorization. This makes it safe to expose on the web, but
prevents us from doing POST/PUT/DELETE. ..

You can enable it using tastypie.authorization.Authorization:

from tastypie.authorization import Authorization
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()
        authorization= Authorization() # <---

Warning

This is now great for testing in development but VERY INSECURE.
You should never put a Resource like this out on the internet. Please
spend some time looking at the authentication/authorization classes
available in Tastypie.

👤falsetru

Leave a comment