RequestMethodMiddleware¶
Adds the request’s method as boolean properties to the request object.
Note
Make sure to install dj_angles middleware to access this functionality.
Example¶
# views.py
from django.shortcuts import render
from book.models import Book
def book(request, book_id):
book = Book.objects.filter(id=book_id).first()
if request.is_post:
book.name = request.POST.get('name')
book.save()
return redirect('book', id=book.id)
return render(request, 'book.html', {'book': book})
Properties¶
request.is_postrequest.is_getrequest.is_patchrequest.is_headrequest.is_putrequest.is_deleterequest.is_trace