![]() ![]() parse() are: streamĪ stream-like object representing the body of the request. The method should return the data that will be used to populate the request.data property. parse(self, stream, media_type, parser_context) method. To implement a custom parser, you should override BaseParser, set the. See the Django documentation for more details.ĭef put(self, request, filename, format=None): FileUploadParser respects Django's standard FILE_UPLOAD_HANDLERS setting, and the request.upload_handlers attribute.Since this parser's media_type matches any content type, FileUploadParser should generally be the only parser set on an API view.For web-based uploads, or for native clients with multipart upload support, you should use the MultiPartParser instead. The FileUploadParser is for usage with native clients that can upload the file as a raw data request.For example Content-Disposition: attachment filename=upload.jpg. If it is called without a filename URL keyword argument, then the client must set the filename in the Content-Disposition HTTP header. If the view used with FileUploadParser is called with a filename URL keyword argument, then that argument will be used as the filename. The request.data property will be a dictionary with a single key 'file' containing the uploaded file. media_type: multipart/form-data FileUploadParser request.data and request.FILES will be populated with a QueryDict and MultiValueDict respectively. Parses multipart HTML form content, which supports file uploads. media_type: application/x-www-form-urlencoded MultiPartParser You will typically want to use both FormParser and MultiPartParser together in order to fully support HTML form data. request.data will be populated with a QueryDict of data. request.data will be populated with a dictionary of data. For example, the following settings would allow only requests with JSON content, instead of the default of JSON or form data. The default set of parsers may be set globally, using the DEFAULT_PARSER_CLASSES setting. If you don't set the content type, most clients will default to using 'application/x-ajax() method, you should make sure to include the contentType: 'application/json' setting. Note: When developing client applications always remember to make sure you're setting the Content-Type header when sending data in an HTTP request. When request.data is accessed, REST framework will examine the Content-Type header on the incoming request, and determine which parser to use to parse the request content. The set of valid parsers for a view is always defined as a list of classes. There is also support for defining your own custom parsers, which gives you the flexibility to design the media types that your API accepts. REST framework includes a number of built-in Parser classes, that allow you to accept requests with various media types. Malcom Tredinnick, Django developers group Sending more complex data than simple forms Structured formats for sending data than form-encoded, since they're Machine interacting web services tend to use more ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |