Using SimpleRouter and can't perform PUT, DELETE, PATCH from Ajax. 405 METHOD NOT ALLOWED

4,091 views
Skip to first unread message

James Pacileo

unread,
Jun 17, 2013, 11:53:31 AM6/17/13
to django-res...@googlegroups.com
Hi,

I'm using the SimpleRouter tuorial within the docs.

Just to test I've created a temporary Authentication class:

class BackboneBasicAuthentication(authentication.BaseAuthentication):
    def authenticate(self, request):
        user = User.objects.filter(username="james")
        return (user, None)

 settings look like this

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'core.rest_authentication.BackboneBasicAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
       'rest_framework.permissions.AllowAny',
    ),
}

 Submitting a PUT request returns a 405 METHOD NOT ALLOWED

{"detail": "Method 'PUT' not allowed."}

I've tried with  X-HTTP-Method-Override as well. No go.

Any ideas what I'm doing wrong? I've spent a whole day trying to figure this out, hopefully someone can help.

Regards,
James

Tom Christie

unread,
Jun 17, 2013, 12:47:03 PM6/17/13
to django-res...@googlegroups.com
Hi James,

  The 405 response is because the view doesn't have a 'put' method.
  What do the views you're testing look like?
  I'd keep thing simple, and drop the authentication class while you're testing - do you still get the same response?
  One other obvious thing to note, you mention this line...

  user = User.objects.filter(username="james")

  which should probably be...

  user = User.objects.get(username="james")

  As right now it looks like you're returning a queryset rather than a user instance from your authentication class.

Regards,

  Tom

James Pacileo

unread,
Jun 20, 2013, 6:26:18 AM6/20/13
to django-res...@googlegroups.com
Hi Tom,
 
thanks for the response! It all seems to be working now.
Spent ages trying to figure this out, so happy I can finally use it. :)
 
James
 


--
You received this message because you are subscribed to a topic in the Google Groups "Django REST framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-rest-framework/FXhJ3PDjwqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sven Mäurer

unread,
Mar 24, 2015, 6:53:10 AM3/24/15
to django-res...@googlegroups.com
I have the same problem. What was your solution?
To unsubscribe from this group and all its topics, send an email to django-rest-framework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages