Django的REST框架 - 405方法使用SimpleRouter NOT ALLOWED [英] Django REST Framework - 405 METHOD NOT ALLOWED using SimpleRouter
问题描述
我使用的文档中的SimpleRouter tuorial。
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',
),
}
提交PUT请求返回405不允许的方法
Submitting a PUT request returns a 405 METHOD NOT ALLOWED
{"detail": "Method 'PUT' not allowed."}
我使用X-HTTP-方法,覆盖试过为好。没有去。
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! :)
推荐答案
要我说,似乎是由路由视图集不执行或不允许PUT请求引起的。如果这是一个身份验证问题,你会得到一个 401未授权
状态code。
To me that seems to be caused by the routed viewset not implementing or not allowing PUT requests. If it was an authentication issue, you would get a 401 UNAUTHORIZED
status code.
这篇关于Django的REST框架 - 405方法使用SimpleRouter NOT ALLOWED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!