Http Delete request to django returns a 301(Moved permenantly)

后端 未结 2 1125
温柔的废话
温柔的废话 2020-12-29 04:18

When I do a Http DELETE request to a django app. it directly returns a 301(Moved permanantly) response and redirects me to GET request of same url. I am guessing that Http P

2条回答
  •  [愿得一人]
    2020-12-29 04:45

    I ran into this issue while using AngularJs and Django REST.

    Django Rest was redirecting the client in order to request the URL with a trailing slash while AngularJS' $resource ensures there is not a trailing dash on its URLs. This is described in this issue

    On the same link you will see suggestions to use the more flexible $http service instead of $resource. But... I really wanted to use $resource (less code).

    So the solution was trivial, since the Django REST team have accounted for this recently:

    router = DefaultRouter(trailing_slash=False)
    

    http://django-rest-framework.org/api-guide/routers.html

    (I've added to this to my blog since I'd like to keep a log of a few gotchas using AngularJS & Django REST)

提交回复
热议问题