Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>TL;DR:</strong> <code>request.method</code> is never <code>None</code> in real use, but for your particular case, you're looking at the wrong thing.</p> <h1>Generic <code>HttpRequest</code></h1> <p><code>django/http/__init__.py</code>:</p> <pre><code>class HttpRequest(object): ... def __init__(self): ... self.method = None ... </code></pre> <p>When a plain <code>HttpRequest</code> is instantiated, its method is <code>None</code>. But then, <code>WSGIRequest</code> and <code>ModPythonRequest</code> don't call <code>HttpRequest.__init__</code> ever.</p> <h1>Requests through <code>mod_wsgi</code></h1> <p><code>django/core/handlers/wsgi.py</code>:</p> <pre><code>class WSGIRequest(http.HttpRequest): ... def __init__(self, environ): ... self.method = environ['REQUEST_METHOD'].upper() ... </code></pre> <p>The summary of this is that for mod_wsgi, <code>request.method</code> will <em>never</em> be <code>None</code>. If in some warped way you managed to get <code>environ['REQUEST_METHOD']</code> not being defined or being <code>None</code>, the request would fail.</p> <h1>Requests through <code>mod_python</code></h1> <p><code>django/core/handlers/modpython.py</code>:</p> <pre><code>class ModPythonRequest(http.HttpRequest): ... def _get_method(self): return self.META['REQUEST_METHOD'].upper() ... method = property(_get_method) </code></pre> <p>Same remarks as with <code>WSGIRequest</code> apply. Can't ever be <code>None</code>.</p> <h1>Test client</h1> <p><code>django.test.client.RequestFactory.request</code> instantiates a <code>WSGIRequest</code> and is called every time with <code>REQUEST_METHOD</code> defined in the <code>environ</code> as an uppercase string, as it should be.</p> <hr> <p><strong>Summary:</strong></p> <pre><code>assert request.method is not None </code></pre> <p>You're looking for the error in the wrong place. In this case, <code>request.method == 'POST'</code>. It's failing when <code>request.META.get('CONTENT_TYPE', '') is None</code>. The reason for this is that the <code>Content-Type</code> header isn't being sent by the client in the request (don't ask me why, I'm not familiar with that stuff).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload