[英]{ "detail": "Method \"GET\" not allowed." }
So the problem I have already mentioned.所以我已经提到的问题。 I am a beginner, I might be doing some silly mistakes.我是初学者,我可能会犯一些愚蠢的错误。 So humble request to you guys to address my mistake and help me to complete my project.非常谦虚地请求你们解决我的错误并帮助我完成我的项目。 Thanks you all in advance.提前谢谢大家。
setting.py设置.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
JWT_AUTH = {
'JWT_ALLOW_REFRESH': True,
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600),
}
this is the setting.py file and here I mention the required file这是 setting.py 文件,这里我提到了所需的文件
view.py查看.py
class LoginViewSet(viewsets.ViewSet):
""" Check email and password and return auth token. """
serializer_class = AuthTokenSerializer
authentication_classes((SessionAuthentication, TokenAuthentication, BasicAuthentication))
permission_classes((IsAuthenticated,))
def create(self, request):
""" Use ObtainAuthToken APIView to validate and create a token. """
return ObtainAuthToken().post(request)
this is the view.py file.这是 view.py 文件。
urls.py网址.py
router.register('login', views.LoginViewSet, base_name="login")
urlpatterns = [
path('', include(router.urls)),
path('login/', ObtainAuthToken.as_view()),
path(r'api-token-auth/', obtain_jwt_token),
path(r'api-token-refresh/', refresh_jwt_token),
]
you must define http_method_names
in DRF and specify your method access in your api.您必须在 DRF 中定义http_method_names
并在您的 api 中指定您的方法访问。
class IndexViewAPI(generics.GenericAPIView):
http_method_names = ['get', 'head']
# some statements
So the problem I have already mentioned.所以我已经提到了这个问题。 I am a beginner, I might be doing some silly mistakes.我是一个初学者,我可能会犯一些愚蠢的错误。 So humble request to you guys to address my mistake and help me to complete my project.因此,请您谦虚地解决我的错误并帮助我完成我的项目。 Thanks you all in advance.预先谢谢大家。
setting.py setting.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
JWT_AUTH = {
'JWT_ALLOW_REFRESH': True,
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600),
}
this is the setting.py file and here I mention the required file这是setting.py文件,在这里我提到了所需的文件
view.py view.py
class LoginViewSet(viewsets.ViewSet):
""" Check email and password and return auth token. """
serializer_class = AuthTokenSerializer
authentication_classes((SessionAuthentication, TokenAuthentication, BasicAuthentication))
permission_classes((IsAuthenticated,))
def create(self, request):
""" Use ObtainAuthToken APIView to validate and create a token. """
return ObtainAuthToken().post(request)
this is the view.py file.这是view.py文件。
urls.py urls.py
router.register('login', views.LoginViewSet, base_name="login")
urlpatterns = [
path('', include(router.urls)),
path('login/', ObtainAuthToken.as_view()),
path(r'api-token-auth/', obtain_jwt_token),
path(r'api-token-refresh/', refresh_jwt_token),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.