🌵

How to Set Up djangorestframework-camel-case

This article was automatically translated from theJapanese original by AI. It may contain translation errors.

This post was published over 1 year ago. Its content may be outdated.

Overview

djangorestframework-camel-case is a library that automatically converts keys to camelCase when DRF returns a JSON response.

Example

For instance, when you call an API that returns user information:

{
	username: "Yuji",
	created_at: "2025-01-01",
}

It becomes this:

{
 	username: "Yuji",
 	createdAt: "2025-01-01",
}

Frontend languages often use camelCase, so this lets you keep things consistent.

Setup

Installing the library

In a pipenv environment, you can install it with the following command.

pipenv install djangorestframework-camel-case

Then add the following to REST_FRAMEWORK in settings.py (add the setting if it doesn’t exist), and the setup is complete.

REST_FRAMEWORK = {
    "DEFAULT_RENDERER_CLASSES": (
        "djangorestframework_camel_case.render.CamelCaseJSONRenderer",
        "djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer",
    ),
    "DEFAULT_PARSER_CLASSES": (
        "djangorestframework_camel_case.parser.CamelCaseFormParser",
        "djangorestframework_camel_case.parser.CamelCaseMultiPartParser",
        "djangorestframework_camel_case.parser.CamelCaseJSONParser",
    ),
}

Recent Articles

Network(beta)

Drag to move / Ctrl+wheel to zoom