Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Parser for nested params in multipart file upload

Project description

drf-nested-multipart-parser

DRF Parser for nested params in multipart file upload.

Usage

from drf_nested_multipart_parser import NestedMultipartParser
from rest_framework import viewsets

class YourViewSet(viewsets.ViewSet):
	parser_classes = (NestedMultipartParser,)

To enable JSON and multipart

from drf_nested_multipart_parser import NestedMultipartParser
from rest_framework.parsers import JSONParser
from rest_framework import viewsets

class YourViewSet(viewsets.ViewSet):
	parser_classes = (JSONParser, NestedMultipartParser)

Example:

Input data

user[email] = 'test@test.test'
user[name] = 'John Doe'

user[profile][balance] = 100.00
user[profile][phone_number] = '+996325698201'
user[profile][avatar] = avatar_file

user[roles][] = 1 
user[roles][] = 2 
user[roles][] = 3 
...

View

from drf_nested_multipart_parser import NestedMultipartParser
from rest_framework import viewsets

class YourViewSet(viewsets.ViewSet):
	parser_classes = (NestedMultipartParser,)

    def post(self, request):
       user_data = request.data.get('user')

       email = user_data['email']  # test@test.test
       balance = user_data['profile']['balance'] # 100.0
       roles = user_data['roles'] # [1, 2, 3]
       ...   

Installation

pip install drf-nested-multipart-parser

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for drf-nested-multipart-parser, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size drf_nested_multipart_parser-0.0.2-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size drf-nested-multipart-parser-0.0.2.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page