Django supports parsing the content of an HTTP request, but only for form POST requests.
That behavior is sufficient for dealing with standard HTML forms, but it doesn’t map well
to general HTTP requests.
We need a method to be able to:
1.) Determine the parsed content on a request for methods other than POST (eg typically also PUT)
- 2.) Determine the parsed content on a request for media types other than application/x-www-form-urlencoded
- and multipart/form-data. (eg also handle multipart/json)
-
class parsers.BaseParser(view)[source]
All parsers should extend BaseParser, specifying a media_type attribute,
and overriding the parse() method.
-
can_handle_request(content_type)[source]
Returns True if this parser is able to deal with the given content_type.
The default implementation for this function is to check the content_type
argument against the media_type attribute set on the class to see if
they match.
This may be overridden to provide for other behavior, but typically you’ll
instead want to just set the media_type attribute on the class.
-
parse(stream)[source]
Given a stream to read from, return the deserialized output.
Should return a 2-tuple of (data, files).
-
class parsers.JSONParser(view)[source]
Parses JSON-serialized data.
-
parse(stream)[source]
Returns a 2-tuple of (data, files).
data will be an object which is the parsed content of the response.
files will always be None.
-
class parsers.PlainTextParser(view)[source]
Plain text parser.
-
parse(stream)[source]
Returns a 2-tuple of (data, files).
data will simply be a string representing the body of the request.
files will always be None.
-
class parsers.FormParser(view)[source]
Parser for form data.
-
parse(stream)[source]
Returns a 2-tuple of (data, files).
data will be a QueryDict containing all the form parameters.
files will always be None.
-
class parsers.MultiPartParser(view)[source]
Parser for multipart form data, which may include file data.
-
parse(stream)[source]
Returns a 2-tuple of (data, files).
data will be a QueryDict containing all the form parameters.
files will be a QueryDict containing all the form files.
-
class parsers.XMLParser(view)[source]
XML parser.
-
parse(stream)[source]
Returns a 2-tuple of (data, files).
data will simply be a string representing the body of the request.
files will always be None.