I would like my Django rest framework API's to accept only Json data. So i set it in the default settings.
REST_FRAMEWORK = {
...
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
],
}
but the views are still accepting the multipart form-data and x-www-form-urlencoded.
If i set the MultiPartParser in view than only multi form data is accepted , If i set the JSONParser in view than both multi form data and json is accepted.
How can i make it to accept only json data by default and multi-part only for a view in which i am uploading a file?
If I'm comprehending it correct, you need to specify REST_FRAMEWORK variable in settings like this
REST_FRAMEWORK = {
...
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
],
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With