Metadata-Version: 2.5
Name: django-spec-html
Version: 0.1.1
Summary: A django-service-specs spec as a server-rendered page, HTML first and htmx-capable, plus the plain-Django JSON views.
Project-URL: Homepage, https://github.com/Artui/django-spec-html
Project-URL: Repository, https://github.com/Artui/django-spec-html
Project-URL: Issues, https://github.com/Artui/django-spec-html/issues
Author-email: Artur Veres <artur8118@gmail.com>
License: MIT
License-File: LICENSE
Keywords: dispatch,django,forms,html,htmx,services,specs,views
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: django-service-specs>=0.12.0
Requires-Dist: django>=4.2
Description-Content-Type: text/markdown

# django-spec-html

[![CI](https://github.com/Artui/django-spec-html/workflows/tests/badge.svg)](https://github.com/Artui/django-spec-html/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/django-spec-html.svg)](https://pypi.org/project/django-spec-html/)
[![Python versions](https://img.shields.io/pypi/pyversions/django-spec-html.svg)](https://pypi.org/project/django-spec-html/)
[![Django versions](https://img.shields.io/pypi/djversions/django-spec-html.svg)](https://pypi.org/project/django-spec-html/)
[![Docs](https://img.shields.io/badge/docs-artui.github.io-blue.svg)](https://artui.github.io/django-spec-html/)
[![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Artui/django-spec-html/gh-pages/coverage.json)](https://github.com/Artui/django-spec-html/actions/workflows/tests.yml)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![License](https://img.shields.io/pypi/l/django-spec-html.svg)](https://github.com/Artui/django-spec-html/blob/main/LICENSE)


A [`django-service-specs`](https://github.com/Artui/django-service-specs) spec
served over plain Django, with no API framework between the request and the
kernel's `dispatch`. `SpecFormView` serves a spec whose Validator is a Django
form as the page a person fills that form in on, and a refused post comes back
as the page again with the refusal placed on its form. Beside the pages,
`SpecView`, `AsyncSpecView` and `dispatch_request` serve a spec as JSON, for a
script, a `fetch()` or an htmx request.

Both halves are the kernel's, moved out with their history so the kernel
carries no transport: the JSON views as kernel 0.11.0 shipped them, and
`SpecFormView` as kernel 0.5.1 did. The behaviour is the kernel's, but for
the page answering an `UnsupportedMediaType` an operation raises at 415 where
the kernel's answered 400; the import path is this package's. The kernel no
longer ships these names: import them from `django_spec_html`.

## Install

```bash
pip install django-spec-html
```

Python 3.10 or later, Django 4.2 or later, and `django-service-specs` 0.12.0 or
later, which it installs. Neither package needs an entry in `INSTALLED_APPS`.

## Quickstart

A page, for a spec whose Validator is a `FormValidator`. GET renders the form;
a valid POST dispatches and redirects; a refused one renders the form again
with the refusal on it:

```python
# yourapp/urls.py
from django.urls import path, reverse_lazy
from django_spec_html import SpecFormView

from yourapp.specs import add_book_spec  # a ServiceSpec with a FormValidator

urlpatterns = [
    path(
        "books/add/",
        SpecFormView.as_view(
            spec=add_book_spec,
            template_name="books/add.html",  # renders {{ form }} in a POST form
            success_url=reverse_lazy("books"),
        ),
    ),
]
```

A JSON view, for any spec. The view reads the arguments from the query string
or the body and the route, dispatches, and answers the presented result, or
the refusal at its status:

```python
from django.urls import path
from django_spec_html import SpecView

from yourapp.specs import list_notes_spec, rename_note_spec

urlpatterns = [
    path("notes/", SpecView.as_view(spec=list_notes_spec)),
    path("notes/<int:pk>/rename/", SpecView.as_view(spec=rename_note_spec)),
]
```

## Documentation

<https://artui.github.io/django-spec-html/>

## License

MIT. See [LICENSE](https://github.com/Artui/django-spec-html/blob/main/LICENSE).
