mirror of
https://github.com/django/django.git
synced 2025-04-15 04:44:37 +00:00
Doc'd BaseParser, FormParser and MultiPartParser
This commit is contained in:
parent
0fd67b89ef
commit
476501242c
@ -21,6 +21,7 @@ API Reference
|
||||
migration-operations
|
||||
models/index
|
||||
paginator
|
||||
parsers
|
||||
request-response
|
||||
schema-editor
|
||||
settings
|
||||
|
58
docs/ref/parsers.txt
Normal file
58
docs/ref/parsers.txt
Normal file
@ -0,0 +1,58 @@
|
||||
============
|
||||
HTTP Parsers
|
||||
============
|
||||
|
||||
.. module:: django.http.parsers
|
||||
:synopsis: Classes dealing with parsing HTTP requests.
|
||||
|
||||
# TODO See about stitching this back into ``request-response.txt``
|
||||
|
||||
Parsers
|
||||
=======
|
||||
|
||||
.. class:: BaseParser
|
||||
|
||||
.. attribute:: media_type
|
||||
|
||||
The media types this class can accept. Example ``application/json``.
|
||||
|
||||
.. method:: can_handle(media_type)
|
||||
|
||||
This method accepts a media type and returns true if the parser can parse
|
||||
this type. By default, this method compares the string provided to
|
||||
:attr:`.media_type` and returns ``True`` if it's an exact match.
|
||||
|
||||
You may wish to customize this method if your custom parser can accept
|
||||
multiple types.
|
||||
|
||||
.. method:: BaseParser.parse(request)
|
||||
|
||||
This method parses the requests body and returns a two-tuple being the
|
||||
parsed ``data`` and ``FILES``. For parsers which do not return ``FILES`` an
|
||||
empty ``MultiValueDict`` is returned.
|
||||
|
||||
All parsers should inherit from the ``BaseParser`` class. This class has the
|
||||
following attributes and methods
|
||||
|
||||
Provided parsers
|
||||
================
|
||||
|
||||
Django provides the following parsers.
|
||||
|
||||
.. class:: FormParser
|
||||
|
||||
.. attribute:: media_type
|
||||
|
||||
``"application/x-www-form-urlencoded"``
|
||||
|
||||
Parses HTML form content (). The ``parse()`` method returns a
|
||||
``QueryDict`` for ``data`` and an empty ``MultiValueDict`` for ``FILES``.
|
||||
|
||||
.. class:: MultiPartParser
|
||||
|
||||
.. attribute:: media_type
|
||||
|
||||
``"multipart/form-data"``
|
||||
|
||||
Parses multipart form content and supports file uploads. The method returns
|
||||
a ``QueryDict`` for ``data`` and an ``MultiValueDict`` for ``FILES``.
|
Loading…
x
Reference in New Issue
Block a user