I am working on a web app using Django. I created one GET API User/GetUserName.aspx. I started the Django development server. On accessing the URL from browser, I am able to hit this API. Now, there is existing system which sends the request to same API to another server. I configured it to send the request to my app. I am receiving the request but Django returns 404 error.

On debugging I found that when I send request from my browser or any other system, I receive request like /User/GetUserName.aspx. However, the existing system to which I want to communicate shows request as / Where IP is my system IP and port is where django app is running.

I tried developing same REST API in flask, there it works without any additional changes as it works for local browser.

I also tried adding middlware and clipping extra part from the API request but still same issue.

Can anyone suggest what could be the reason behind this issue and way to fix it?

Is the trailing slash at the beginning of the URL intentional?

The first step I’d do is try to understand where in the chain the error is coming from. If you replace the view with a simple view which just returns HttpResponse, and have the other system request that, you’ll see one of 2 things:

  1. A 200, in which case it’s the view which is throwing the 400 incorrectly. You’ll want to look into any filtering or permissions it’s doing
  2. A 404, in which case the issue is in the request even finding the right view. This could be a misconfiguration in the other system, or something else in Django 404-ing the request (perhaps middleware).

In either case, make sure the logs for you loading the page vs the existing system look as identical as possible.

The slash at the beginning is what I saw in the get request received as printed by Django.

My current view is simple one returning a HttpResponse with 200 and a text message.

If I access the url like from local browser, postman or any other machine on same network the API get hit with Django terminal showing GET /User/GetUserName.aspx.

But when device send the request, the Django prints GET not found.

I am not sure why it shows the GET request differently in these cases.