BAE BAE - 1 year ago 104
Python Question

Django: URL trailing slash issue

url(r'^v1/files/$', MyFileView.as_view(), name='api-upload'),
url(r'^v1/files/$', MyFileView.as_view(), name='api-view-all'),

class MyFileView(APIView):
def post():
def get():

My question is: why
POST api/v1/files
works like
GET api/v1/files/
? I thought
POST api/v1/files
should return 404. Anything wrong?


does not have this issue.
will return 404.

Answer Source

I think that they don't "work like GET".

What is really happening is that:

  • you send a POST url
  • the server replies with a HTTP 302 to url/
  • and the browser performs a GET url/.

And the result of that is what you actually see.

If you check the requests being actually sent along the wire, I suspect you'll see two requests - the first being the POST, the second being the GET.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download