Adds a boolean property to the request for the current request’s HTTP method.


Add "fbv.middleware.RequestMethodMiddleware" to the MIDDLEWARE list in settings.py. It doesn’t matter where in the list it is added, but it probably shouldn’t be first.

# settings.py
    # other middleware
    # other middleware

request properties

Once the middleware is installed every request object will now have a boolean property for each of the following HTTP methods:

  • is_post

  • is_get

  • is_patch

  • is_head

  • is_put

  • is_delete

  • is_connect

  • is_trace

# views.py
from fbv.decorators import render_html

def sample_html_view(request):
    if request.is_get:  # instead of `request.method == "GET"`
        return {"http_method": "GET"}
    elif request.is_post:  # instead of `request.method == "POST"`
        return {"http_method": "POST"}