Django post response method post not allowed

3,075 views
Skip to first unread message

Shekar Tippur

unread,
May 28, 2015, 9:58:06 AM5/28/15
to django...@googlegroups.com
Hello,

I am trying to post a request via curl. 

curl -H  "Authorization: Bearer $usertoken" -X POST -d '{"username":"foo1","object":"XYZ","prefs":"likes"}' http://${endpoint}/setProfile/


Here is the entry in my urls.py

url(r'^setProfile/', AddToUserProfile),

class AddToUserProfile(generics.ListAPIView):
queryset = UserPrefs.objects.all()
serializer_class = UserPrefSerializer

class UserPrefSerializer(serializers.ModelSerializer):
class Meta:
model = UserPrefs
fields = ('id', 'prefs', 'obj_id', 'user_id')
depth = 1

I get a response - {"detail":"Method \"POST\" not allowed."}

Is there anything else I need to specify?

- Shekar

Filipe Ximenes

unread,
May 28, 2015, 11:47:01 AM5/28/15
to django...@googlegroups.com
I assume you are using Django REST Framework. 
ListAPIViews only accepts GET requests, because well, it's supposed only to list stuff. If you need to add data, try the CreateAPIView, or depending on what you want, a ListCreateAPIView.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d8db1691-e60d-4a46-9598-47227bd4c6e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
  
Filipe Ximenes
+55 (81) 8245-9204
Vinta Software Studio
http://www.vinta.com.br
Reply all
Reply to author
Forward
0 new messages