Skip to main content

Django Headless

PyPI version Python versions Django versions License

Django Headless generates a REST API for your Django models, so Django can serve as the backend of a headless CMS. Decorate a model with @expose() and it gets list, detail, create, update and delete routes, with no serializers, viewsets or URL patterns to write.

Read the documentation at djangoheadless.org.

Features

  • Routes per model: one decorator generates the routes of a model.
  • Singletons: site settings and other one-off objects as a single route.
  • Filtering: every lookup a field supports, from the query string.
  • Lookup routes: fetch an object by a unique field such as a slug, at /api/blog.article/by_slug/<value>.
  • Pagination: a stable, paginated list envelope with ready-to-fetch links.
  • Protected by default: generated routes only answer staff users until you open them up.

Quick start

  1. Install the package:

    pip install django-headless
    
  2. Add rest_framework, headless and headless.rest to INSTALLED_APPS:

    # mysite/settings.py
    INSTALLED_APPS = [
        # ...
        "rest_framework",
        "headless",
        "headless.rest",
    ]
    
  3. Include the API in your URL configuration:

    # mysite/urls.py
    from django.urls import include, path
    
    urlpatterns = [
        # ...
        path("api/", include("headless.rest.urls")),
    ]
    
  4. Expose a model:

    # blog/models.py
    from django.db import models
    from headless import expose
    
    
    @expose()
    class Article(models.Model):
        title = models.CharField(max_length=200)
        body = models.TextField()
        published = models.BooleanField(default=False)
        created_at = models.DateTimeField(auto_now_add=True)
    
        def __str__(self):
            return self.title
    

Run python manage.py runserver; the article list is at /api/blog.article.

Generated routes answer 403 Forbidden to everyone but staff users, so an exposed model is never public by accident. To configure authentication or open the routes up, see Permissions.

Documentation

Contributing

To contribute a change:

  1. Fork the repository.
  2. Create a branch: git checkout -b fix-boolean-casting.
  3. Make the change and add tests for it.
  4. Run the test suite: poetry run python scripts/test_wrapper.py test.
  5. Commit and push the branch.
  6. Open a pull request.

Set up a development environment with Poetry:

git clone https://github.com/dwarsbit/django-headless.git
cd django-headless
poetry install
poetry run python scripts/test_wrapper.py test

Writing for the README or the documentation follows STYLE.md.

Support

License

Django Headless is licensed under the MIT License; see LICENSE.

Metadata

Release files for django-headless 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-headless 1.0.0
File Size Uploaded Provenance
django_headless-1.0.0.tar.gz 31.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-headless 1.0.0
File Interpreter ABI Platform
django_headless-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 71.3 kB

Release files / django_headless-1.0.0.tar.gz

Download URL django_headless-1.0.0.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8dcfc710f6cb92304aa61568db0191f932a652435d3749768d4c5fd03a184381
BLAKE2b-256 checksum
How to use checksums
0d73313d85716adfca2719ab848eb2cdeedb15316bd1b4d0562dae7e4f30f2b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.9 Darwin/27.0.0

Release files / django_headless-1.0.0-py3-none-any.whl

Download URL django_headless-1.0.0-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf5be15dbe56fda8597823465150eaa1241786bbd2f3ee5c4c10e224bb19957b
BLAKE2b-256 checksum
How to use checksums
7ea0b3b6cdf530dd263bc93ad0c5557e4716e9993ffc3a7b65ede309b0989f96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.9 Darwin/27.0.0

Security for django-headless 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page