Mourad Qqch
Mourad Qqch

Reputation: 459

Django and nginx do not accept PATCH requests, resulting in a 400 bad request error

I work on a Django project + django-rest-framework. On localhost, PATCH requests work perfectly fine. However, on server, PATCH requests do not work. I get a 400 Bad request error. I use nginx to configure the web server.

Here is my configuration:

server {
    listen 80;
    server_name x.y.z.com;
    root /var/www/path-to/project;

    location / {
            error_page 404 = 404;
            proxy_pass  http://127.0.0.1:5555/;
            proxy_set_header Host $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_intercept_errors on;
    }
}

I get this error when I try PATCH requests on server :

enter image description here

How can I make so that django accept PATCH requests? The log does not show anything. As if it does not even receives the request. I run the django server like this:

python manage.py runserver 5555

Upvotes: 1

Views: 1253

Answers (1)

Julian Pedro Braga
Julian Pedro Braga

Reputation: 116

Friend, I faced this problem, I made all the possible settings in nginx, but the problem was in my js fetch that tried with the patch method in lowercase, 'patch', changing to 'PATCH' worked normally.

Upvotes: 10

Related Questions