I am trying to figure out this issue related to Django from https://github.com/miki725/Django-jQuery-File-Uploader-Integration-demo/issues/1
Under what conditions can request.method == None in Django?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
TL;DR:
request.methodis neverNonein real use, but for your particular case, you’re looking at the wrong thing.Generic
HttpRequestdjango/http/__init__.py:When a plain
HttpRequestis instantiated, its method isNone. But then,WSGIRequestandModPythonRequestdon’t callHttpRequest.__init__ever.Requests through
mod_wsgidjango/core/handlers/wsgi.py:The summary of this is that for mod_wsgi,
request.methodwill never beNone. If in some warped way you managed to getenviron['REQUEST_METHOD']not being defined or beingNone, the request would fail.Requests through
mod_pythondjango/core/handlers/modpython.py:Same remarks as with
WSGIRequestapply. Can’t ever beNone.Test client
django.test.client.RequestFactory.requestinstantiates aWSGIRequestand is called every time withREQUEST_METHODdefined in theenvironas an uppercase string, as it should be.Summary:
You’re looking for the error in the wrong place. In this case,
request.method == 'POST'. It’s failing whenrequest.META.get('CONTENT_TYPE', '') is None. The reason for this is that theContent-Typeheader isn’t being sent by the client in the request (don’t ask me why, I’m not familiar with that stuff).