Reputation: 404
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?
Upvotes: 2
Views: 2871
Reputation: 16733
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',
],
}
Upvotes: 9