Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从AngularJS发布到Django API以获取JWT并返回405错误_Angularjs_Django_Http_Post_Jwt - Fatal编程技术网

从AngularJS发布到Django API以获取JWT并返回405错误

从AngularJS发布到Django API以获取JWT并返回405错误,angularjs,django,http,post,jwt,Angularjs,Django,Http,Post,Jwt,当我在接收POST请求的端点中获取令牌时,得到了405 我正在使用rest\u框架和rest\u框架\u jwt 终点: from django.conf.urls import url from django.contrib import admin from rest_framework_jwt.views import obtain_jwt_token from rest_framework_jwt.views import refresh_jwt_token from rest_fram

当我在接收POST请求的端点中获取令牌时,得到了405

我正在使用rest\u框架和rest\u框架\u jwt

终点:

from django.conf.urls import url
from django.contrib import admin
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework_jwt.views import refresh_jwt_token
from rest_framework_jwt.views import verify_jwt_token

urlpatterns = [
    url(r'^$', IndexView.as_view(), name='index'),
    url(r'^api/api-token-auth/', obtain_jwt_token),
    url(r'^api/api-token-verify/', verify_jwt_token),
    url(r'^api/api-token-refresh/', refresh_jwt_token),

]
AngularJS员额:

$scope.login = function () {

          $http.post('api/api-token-auth/',
              {
                'username': $scope.username,
                'password': $scope.password
              })
              .success(function (response) {
                $scope.logged = true;
                $scope.jwt = response.token;
                console.log(response.token);
                store.set('token', response.token);
              },function (response) {
                 $scope.logged = false;
                 console.log(response);
              });
        }

我在《邮递员》中发帖子时也遇到了同样的错误,我发现了问题,在我的路线中,我为AngularJS路线做了如下操作:

url(r'^(?P<path>.*)/$', IndexView.as_view()),

它成功了

您能否将views.py、serializers.py、models.py和settings.py(DRF配置部分)以及在客户端收到的错误消息发布到响应中?HTTP 405错误意味着不允许使用该方法,因此可能是身份验证/授权问题集默认设置或其他地方。无论哪种方式,拥有更多信息都有助于调试它。当请求发送到视图但没有方法处理程序时,您通常会在DRF中看到405。我将在URL配置中用自定义视图替换请求,以确保请求将转到您认为它是的视图。我发现您的URL模式末尾缺少“$”,这可能导致请求转到意外视图。
url(r'^/$', IndexView.as_view()),