Can't PUT ModelViewSet Django Rest Framework
I'm not sure why I can't make PUT requests to my ModelViewSet as shown in the documentation, however PUT doesn't work. Any ideas? I've included my view and serializer below.
class UserProfileViewSet(viewsets.ModelViewSet):
queryset = UserProfile.objects.all()
serializer_class = UserProfileSerializer
filter_fields = ('user', 'id', 'account_type')
class UserProfileSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile`
REST_FRAMEWORK = {
'DEFAULT_MODEL_SERIALIZER_CLASS':
'rest_framework.serializers.ModelSerializer',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
),
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
}
+3
source to share
3 answers
Is it possible that you are not doing the request correctly? You need to specify the object you are trying to update in the url.
For example, the url must include the id of the object you are trying to update: http: // localhost: 8000 / api / user / 16 /
You get "Method \" PUT \ "is not allowed." when you do not specify an object in the request.
+1
source to share