{“ detail”:“不允许使用方法\” GET \“。” }

时间:2019-02-03 12:54:41

标签: python django django-rest-framework

所以我已经提到了这个问题。我是一个初学者,我可能会犯一些愚蠢的错误。因此,请大家谦虚地解决我的错误并帮助我完成我的项目。谢谢大家。

setting.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)

这是setting.py文件,在这里我提到了必需的文件

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

这是view.py文件。

urls.py

let sessionUniqueId = parseInt(Math.random() *10956362 + new Date().getTime())

var filter = { _id: req.sessionID};
var newvalues = { $set:{
                          "uniqueId":sessionUniqueId,
                }};
sessionStore.updateOne(filter, newvalues, function(err) {
                  if (err) {console.log('Failed to attach Session UniqueId');}
              });

req.session.uniqueId = sessionUniqueId;  // also attach to session property

错误消息   error

1 个答案:

答案 0 :(得分:0)

您必须在DRF中定义http_method_names并在api中指定方法访问权限。

class IndexViewAPI(generics.GenericAPIView):
    http_method_names = ['get', 'head']
    # some statements