i'm getting this 405 when i do a POST to get the token in the endpoint that supposed accepts POST requests.
I'm using rest_framework and rest_framework_jwt
Endpoint:
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 POST:
$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);
});
}
I'm getting the same error when doing the POST in Postman
I've found the problem, in my routes i had this for AngularJS routes:
url(r'^(?P<path>.*)/$', IndexView.as_view()),
So i changed to:
url(r'^/$', IndexView.as_view()),
And it worked