Skip to content

sheiun/django-parse-request-body-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Django Parse Request Body Middleware

What is it

Before

def view(request):
    # I want to use request body
    import json
    data = json.loads(request.body)
    ...

Now

def view(request):
    # use request body directly
    request.data

Compatibilities

  • Python 3.5+
  • Django 1.11+, 2.1+, 3.0 not sure

Not sure work fine in other version.

Request body type

  • form-data
  • application/json
  • x-www-form-urlencoded
    • Test needed
  • raw
    • Test needed
  • binary
    • Test needed

Usage

  1. Put middleware.py and util.py to your django projects in same folder.
  2. Add RequsetBodyParseMiddleware to your settings.py.
MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    "<path.to.your.folder>.middleware.RequsetBodyParseMiddleware",
]

About

Parse django request body to QueryDict in middleware

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages