I see that there is a project called djangorestframework-camel-case that allows you to use JavaScript-ish camelCase with underscore_cased fields in Django REST serializers. So basically, I can send:
{ "camelCase": "foo" }
And get it with the following Serializer:
class MySerializer(serializers.Serializer): session_id = serializers.CharField()
Is there something similar for POST data? So, can I send camelCase=foo via POST and get it in the underscore in my serializer?
I tried to implement my own parser based on FormParser:
class CamelCaseFormParser(FormParser): media_type = 'application/x-www-form-urlencoded' def __init__(self): print("initialized") def parse(self, stream, media_type=None, parser_context=None): print("parse") ...
And by adding it to DEFAULT_PARSER_CLASSES in settings.py, while initialized is actually printed, parse not. Thus, it seems that in the case of POST data, the application/x-www-form-urlencoded parser is not used at all.
Since serializers are used like this:
Serializer(data=request.data)
I am thinking of subclassing Serializer and changing data before it is processed further, or even changing it before creating Serializer. But what I ask is a more convenient way that works for all serializers, without subclassing them.
source share