简体   繁体   English

{ "detail": "方法 \\"GET\\" 不允许。" }

[英]{ "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),
]

Error Message error错误信息错误

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),
]

Error Message error错误信息错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DRF:“详细信息”:“方法\\” GET \\“不允许。” - DRF: “detail”: “Method \”GET\“ not allowed.” POST 返回“详细信息”:“不允许使用方法 \"GET\"。” - POST returns "detail": "Method \"GET\" not allowed." "detail": "方法 \\"POST\\" 不允许。" - "detail": "Method \"POST\" not allowed." "detail": "方法 \\"GET\\" 不允许。" 在 TokenAuthentication Django 休息框架中 - "detail": "Method \"GET\" not allowed." in TokenAuthentication Django rest framework django“详细信息”:“方法\\”GET\\“不允许。” (一对多关系) - django “detail”: “Method \”GET\“ not allowed.” (one to many relationship) "detail": "方法 \"GET\" 不允许。" Django Rest 框架 - "detail": "Method \"GET\" not allowed." Django Rest Framework “详细信息”:“方法 \\”GET\\” 不允许。在 Django 中调用端点 - “detail”: “Method \”GET\" not allowed. on calling endpoint in django “详细信息”:“方法 \”GET\“ 不允许。” Django Rest 框架 - “detail”: “Method \”GET\“ not allowed.” Django Rest Framework Restangular删除不工作(是:DJANGO:{“detail”:“方法'删除'不允许。”}) - Restangular remove not working (was: DJANGO: {“detail”: “Method 'DELETE' not allowed.”}) Django REST 框架 - “方法 \”GET\“ 不允许。” - - Django REST framework - “Method \”GET\“ not allowed.” -
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM