Skip to content

Rohan2460/django-json-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JSON request parser middleware for Django

Simple Django middleware for parsing JSON data from HTTP request.

If the Content-Type of a POST request is application/json, the JSON data is parsed and stored in the HttpRequest.json attribute.

HttpRequest.json Data Types

  • Default (Not accessed): None
  • Success: dict
  • Error: Empty dict

Example

from django.http import JsonResponse

def json_check(request):
    if request.method == "POST":
        data = request.json
        return JsonResponse({'message': 'JSON received', 'data': data.get('message')})
    else:
        return JsonResponse({'error': 'Invalid content type or method'}, status=400)

Documentation

For more details on Django middleware, refer to the Django Middleware Documentation.

License

This project is licensed under the MIT License.


Improve the code and adjust it according to your project's needs. Contributions and suggestions are welcome!

About

Simple JSON request parser middleware for Django

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors