404 error when posting a multipart/form-data form

231 views
Skip to first unread message

Manlio Perillo

unread,
Mar 21, 2019, 5:28:30 AM3/21/19
to Django users
I have a Django application that works perfectly fine both on my PC and on a hosting system with CloudLinux and Passenger.
However when I added a form with a file field, I started to get 404 errors on POST.

I tried to remove all the middleware, but the problem is still here.
The error message says that the 404 error was raised by my view, but that's not true; my view is not called at all during a POST request.

What's strange is that I have another Django application on a different hosting account with the same environment and it works fine.
The problem is probably in my application, but I'm unable to find it.

Where should I search to find the cause of the problem?


Thanks
Manlio Perillo

Mohammad Etemaddar

unread,
Mar 21, 2019, 5:56:43 AM3/21/19
to django...@googlegroups.com
Can you send your view here?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/313db9e4-340c-475a-abe6-f12f96213b05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manlio Perillo

unread,
Mar 21, 2019, 9:42:31 AM3/21/19
to Django users
On Thursday, March 21, 2019 at 10:56:43 AM UTC+1, Mohammad Etemaddar wrote:
Can you send your view here?


Here is the URL that reproduce the problem:

and here is the URL that prints the Django environment:

The view code is here:


What I find strange is that if I remove the {{ form }} and uncomment the manual input element, there is no error.

> [...]


Thanks
Manlio Perillo

Manlio Perillo

unread,
Mar 22, 2019, 6:44:53 AM3/22/19
to Django users
No idea about the cause of the problem?


Thanks
Manlio Perillo

Hamady Medvall

unread,
Mar 22, 2019, 8:28:55 AM3/22/19
to django...@googlegroups.com
You have to add the path /bug in URLConfig

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Manlio Perillo

unread,
Mar 22, 2019, 10:23:32 AM3/22/19
to Django users
On Friday, March 22, 2019 at 1:28:55 PM UTC+1, Hamady Medvall wrote:
You have to add the path /bug in URLConfig


A GET request to /mp/bug/ does not return an error, only a POST request and *only* when using a file upload.

From the trace I see that it's the URL resolver that raises the 404 exception.  But what I don't understand is why a GET request work.

This is the trace for a POST request: https://paste.ee/p/sjq5s


Thanks
Manlio Perillo

Manlio Perillo

unread,
Mar 22, 2019, 11:07:14 AM3/22/19
to Django users
On Friday, March 22, 2019 at 3:23:32 PM UTC+1, Manlio Perillo wrote:
On Friday, March 22, 2019 at 1:28:55 PM UTC+1, Hamady Medvall wrote:
You have to add the path /bug in URLConfig


A GET request to /mp/bug/ does not return an error, only a POST request and *only* when using a file upload.

From the trace I see that it's the URL resolver that raises the 404 exception.  But what I don't understand is why a GET request work.

This is the trace for a POST request: https://paste.ee/p/sjq5s


Some more details.

I have the following main urlpatterns:

urlpatterns = [
    urls.path('mp/', urls.include('lpg.mperillo.urls')),
    ]

And in my application:

urlpatterns = [
    urls.path('bug/', views.bug, name='bug'),
    urls.path('debug/', views.debug, name='debug')
    ]

When accessing https://fast-page.it/mp/bug/, Django tries to match the path `bug` with the pattern `mp` and it fail, raising a 404 exception.
This does not happen with a GET request or with a POST request without a file upload.  Also, I can't reproduce this error on my system, but only on the hosting server.
I have a different Django application on a different account of the same hosting company, and it works correctly.

I originally found the problem in the Django admin, when trying to create a model instance with a file field.


Thanks
Manlio Perillo 

Mohammad Etemaddar

unread,
Mar 22, 2019, 3:09:35 PM3/22/19
to Django users
I'm not sure about this, but I think maybe it would be about your Django bug. Have you updated your Django?

Marcio Bernardes

unread,
Mar 22, 2019, 3:24:28 PM3/22/19
to django...@googlegroups.com
Hey Manlio make sure to change the action option in the form html, use something like {% url ‘url_name’ %} there. Do not use this point path. 

Cheers!

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Raffaele Salmaso

unread,
Mar 22, 2019, 3:35:13 PM3/22/19
to django...@googlegroups.com
On Thu, Mar 21, 2019 at 2:42 PM Manlio Perillo <manlio....@gmail.com> wrote:
I don't see the {% csrf_token %} in the template

--

Manlio Perillo

unread,
Mar 22, 2019, 6:03:03 PM3/22/19
to Django users
On Friday, March 22, 2019 at 8:35:13 PM UTC+1, Raffaele Salmaso wrote:
On Thu, Mar 21, 2019 at 2:42 PM Manlio Perillo <manlio....@gmail.com> wrote:


Because I have remove every extra components.  I removed all the middleware and all the other apps.
However, as I said, this bug occurred original in the django admin app.

I'm using the latest version of Django, and to make sure that the original source files have not been modified, I uninstalled and installed it again.
The bug is still here.

It may be a bug of Passenger (5.3.7), however I checked with a custom wsgi.py file and it sets the PATH_INFO correctly.

This is my view:

As i said at the start of the thread, if I comment the `{{ form }}` and uncomment the `<input type="file" name="xxx">`, Django works correctly.
What I find strange is that it seems the problem is caused by my view (since only my view know the name of the form field), but my view *is not* called, and instead it seems (from the trace file) that the url resolver did not found a match for the request path.


Thanks
Manlio Perillo 

Manlio Perillo

unread,
Apr 24, 2019, 12:53:06 PM4/24/19
to Django users
The problem was caused by Passenger.

Unlike the case from the stackoverflow question, in my case PATH_INFO was incorrectly set only for POST requests containing files.
The fix suggested solved the problem.


Regards
Manlio Perillo
Reply all
Reply to author
Forward
0 new messages