Skip to main content

API endpoints for django CMS

Project description

Latest PyPI version Test coverage Django versions django CMS versions License

djangocms-rest

djangocms-rest enables frontend projects to consume django CMS content through a browsable, read-only REST/JSON API. Built on Django REST Framework (DRF) with OpenAPI 3 schema generation via drf-spectacular.

Key Features

  • Easy integration – Integrates effortlessly into existing Django CMS projects
  • REST API – DRF-based API exposing Django CMS content for SPAs, static sites, and mobile apps
  • Typed Endpoints – Auto-generate OpenAPI schemas for page data and plugin content
  • Plugin Serialization – Basic support for all CMS plugins, easily extendable for custom needs
  • Multi-Site Support – Serve multiple websites from a single instance with isolated API responses
  • Multi-language Content – Use the robust i18n integration of Django CMS in your frontend
  • Preview & Draft Access – Fetch unpublished or draft content in your frontend for editing previews
  • Permissions & Authentication – Uses DRF and Django permissions for secure access control
  • Menus & Breadcrumbs – Exposes the built-in navigation handlers from Django CMS
  • Caching & Performance – Works with Django cache backends like Redis and Memcached

Requirements

  • Python >= 3.10, < 3.14
  • Django >= 4.2, < 6.1
  • Django CMS >= 4.1, < 5.1

Installation

Install using pip:

pip install djangocms-rest

Update your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...
    "djangocms_rest",
    ...
]

rest_framework is installed as a dependency. Add it to INSTALLED_APPS if you want to use the browsable API UI or create additional DRF endpoints beyond djangocms-rest.

Add the API endpoints to your project's urls.py:

from django.urls import path, include

urlpatterns = [
    ...
    path('api/', include('djangocms_rest.urls')),
    ...
]

Using api/cms/ as the path helps separate djangocms-rest endpoints in API documentation and frontend implementation.

Usage

Make sure you have existing pages. If rest_framework is in INSTALLED_APPS, you can navigate to Django REST Framework's browsable API at http://localhost:8000/api/.

Documentation

  • Getting Started – Quick start guide and installation instructions
  • OpenAPI Support – Schema generation and API documentation setup
  • How-to Guides – Multi-site configuration, plugin creation, and serialization
  • API Reference – Complete endpoint documentation

See the full documentation for details.

Headless Mode

What is headless mode?

A Headless CMS (Content Management System) is a backend-only content management system that provides content through APIs, making it decoupled from the frontend presentation layer. This allows developers to deliver content to any device or platform, such as websites, mobile apps, or IoT devices, using any technology stack. By separating content management from content presentation, a Headless CMS offers greater flexibility and scalability in delivering content.

Used with drf-spectacular, djangocms-rest generates complete OpenAPI schemas for both DRF endpoints and Django CMS content plugins. This allows seamless, typed integration with TypeScript-friendly frameworks.

Benefits

  • Decouple frontend and backend development—use any frontend framework (React, Vue, Angular, Next.js, Nuxt, SvelteKit, Remix, Astro, etc.)
  • Serve content to multiple platforms (web, mobile, IoT) via REST/JSON APIs
  • Improved performance through optimized frontend rendering
  • Content updates propagate across all platforms without frontend deployments
  • Easier integration with modern frameworks and third-party services

Considerations

  • Inline editing and content preview are available as JSON views on both edit and preview mode. Turn JSON rendering on and off using the REST_JSON_RENDERING setting.
  • Use Structure Mode in CMS to directly edit content in the frontend when the decoupled view is embedded as an iframe.
  • The API focuses on fetching plugin content and page structure as JSON data. Apphook logic must be implemented using custom logic.
  • Website rendering is entirely decoupled and must be implemented in the frontend framework.

FAQ

Are there JavaScript packages for drop-in support of frontend editing in the JavaScript framework of my choice?

The good news first: django CMS headless mode is fully backend supported and works independently of the javascript framework. It is fully compatible with the javascript framework of your choosing.

How can I implement a plugin for headless mode?

It's pretty much the same as for a traditional django CMS project, see here for instructions on how to create django CMS plugins.

Let's have an example. Here is a simple plugin with two fields to render a custom header. Please note that the template included is just a simple visual helper to support editors to manage content in the django CMS backend. Also, backend developers can now toy around and test their django CMS code independently of a frontend project.

After setting up djangocms-rest and creating such a plugin you can now run the project and see a REST/JSON representation of your content in your browser, ready for consumption by a decoupled frontend.

cms_plugins.py:

# -*- coding: utf-8 -*-
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool

from . import models


class CustomHeadingPlugin(CMSPluginBase):
    model = models.CustomHeadingPluginModel
    module = 'Layout Helpers'
    name = "My Custom Heading"

    # this is just a simple, unstyled helper rendering so editors can manage content
    render_template = 'custom_heading_plugin/plugins/custom-heading.html'

    allow_children = False


plugin_pool.register_plugin(CustomHeadingPlugin)

models.py:

from cms.models.pluginmodel import CMSPlugin
from django.db import models


class CustomHeadingPluginModel(CMSPlugin):

    heading_text = models.CharField(
        max_length=256,
    )

    size = models.PositiveIntegerField(default=1)

templates/custom_heading_plugin/plugins/custom-heading.html:

<h{{ instance.size }} class="custom-header">{{ instance.heading_text }}</h{{ instance.size }}>

Do default plugins support headless mode out of the box?

Yes, djangocms-rest provides out of the box support for any and all django CMS plugins whose content can be serialized.

Custom DRF serializers can be declared for custom plugins by setting its serializer_class property.

Does the TextPlugin (Rich Text Editor, RTE) provide a JSON representation of the rich text?

Yes, djangocms-text has both HTML blob and structured JSON support for rich text.

URLs to other Django model objects are dynamic and resolved to API endpoints if possible. If the referenced model provides a get_api_endpoint() method, it is used for resolution. If not, djangocms-rest tries to reverse <model-name>-detail. If resolution fails dynamic objects are returned in the form of <app-name>.<object-name>:<uid>, for example cms.page:2. The frontend can then use this to resolve the object and create the appropriate URLs to the object's frontend representation.

I don't need pages, I just have a fixed number of content areas in my frontend application for which I need CMS support.

Absolutely, you can use the djangocms-aliases package. It allows you to define custom placeholders that are not linked to any pages. djangocms-rest will then make a list of those aliases and their content available via the REST API.

OpenAPI 3 Support

djangocms-rest supports OpenAPI 3 schema generation for Django REST framework and type generation for all endpoints and installed plugins using drf-spectacular.

API Endpoints

The following endpoints are available:

Public API

Endpoints Description
/api/languages/ Fetch available languages for the site
/api/plugins/ Fetch plugin type definitions for frontend type checks
/api/{language}/pages/ Fetch the root page for a given language
/api/{language}/pages-tree/ Fetch complete page tree (suitable for smaller projects)
/api/{language}/pages-list/ Fetch paginated page list with limit and offset support
/api/{language}/pages/{path}/ Fetch page details by path
/api/{language}/page_search/ Search pages by query term
/api/{language}/placeholders/{content_type_id}/{object_id}/{slot}/ Fetch placeholder content (supports ?html=1 for rendered HTML)
/api/{language}/menu/... Fetch menu navigation (supports optional {from_level}/{to_level}/{extra_inactive}/{extra_active}, {root_id}, and {path} parameters)
/api/{language}/submenu/... Fetch submenu navigation (supports optional {levels}, {root_level}, {nephews}, and {path} parameters)
/api/{language}/breadcrumbs/... Fetch breadcrumb navigation (supports optional {start_level} and {path} parameters)

Documentation
For complete endpoint documentation, request/response schemas, and authentication details, see the API Reference.

Private API (Preview)

For all page related endpoints draft content can be fetched, if the user has the permission to view preview content. To determine permissions user_can_view_page() from djangocms is used, usually editors with is_staff are allowed to view draft content.

Just add the ?preview GET parameter to the above page, page-tree, or page-list endpoints.

Sample API-Response: api/{en}/pages/{sub}/

GET CONTENT using /api/{language}/placeholders/{content_type_id}/{object_id}/{slot}/

{
    "title": "sub",
    "page_title": "sub",
    "menu_title": "sub",
    "meta_description": "",
    "redirect": null,
    "in_navigation": true,
    "soft_root": false,
    "template": "home.html",
    "xframe_options": "",
    "limit_visibility_in_menu": false,
    "language": "en",
    "path": "sub",
    "absolute_url": "/sub/",
    "is_home": false,
    "login_required": false,
    "languages": [
        "en"
    ],
    "is_preview": false,
    "application_namespace": null,
    "creation_date": "2025-02-27T16:49:01.180050Z",
    "changed_date": "2025-02-27T16:49:01.180214Z",
    "placeholders": [
        {
            "content_type_id": 5,
            "object_id": 6,
            "slot": "content"
        },
        {
            "content_type_id": 5,
            "object_id": 6,
            "slot": "cta"
        }
    ]
}

Sample API-Response: api/{en}/placeholders/{5}/{6}/{content}/[?html=1]

Rendered HTML with an optional flag ?html=1

{
    "slot": "content",
    "label": "Content",
    "language": "en",
    "content": [
        {
            "plugin_type": "TextPlugin",
            "body": "<p>Test Content</p>",
            "json": { ... },
            "rte": "tiptap"
        }
    ],
    "html": "<p>Test Content</p>"
}

OpenAPI Type Generation

Use the provided schema to quickly generate generate clients, SDKs, validators, and more.

TypeScript : https://github.com/hey-api/openapi-ts

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

BSD-3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangocms_rest-1.0.0.tar.gz (40.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djangocms_rest-1.0.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_rest-1.0.0.tar.gz.

File metadata

  • Download URL: djangocms_rest-1.0.0.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for djangocms_rest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 01c8340e54073fc71a6e7cf0136528c375c0f667fa1cc99199f6e8859409f609
MD5 0001fdd63f289a7411bde471447fe060
BLAKE2b-256 6315c1aba7d39667de0143657ce794af0cd87ce250533c7809000c56e996a00c

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangocms_rest-1.0.0.tar.gz:

Publisher: publish-to-live-pypi.yml on django-cms/djangocms-rest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djangocms_rest-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: djangocms_rest-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for djangocms_rest-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 333bdf2b0cdcf1b1dcd3b397de825159bda48a478a61cac2a0e0a7f843c3452e
MD5 9904887af597b6e9fe69e6c4bed3e8f4
BLAKE2b-256 380a83c5676fefb59e91043b8f446a01628236b7974ba271fcabf01265334275

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangocms_rest-1.0.0-py3-none-any.whl:

Publisher: publish-to-live-pypi.yml on django-cms/djangocms-rest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page