DRF HTMX Renderer
DRF HTMX Renderer is a (renderer)[https://www.django-rest-framework.org/api-guide/renderers/] for Django REST Framework.
In the vain of the browsable API or the admin renderer shipped with DRF, it allows for browsing the API directly in your browser and making it fully human-friendly.
To learn more about this project, you can watch this talk - Slides available here.
The aim of the project is to provide a customizable and extendable interface for data management that can be presented to the final user.
Install
With pip
pip install drf-htmx-renderer
From github
git clone git@github.com:nanuxbe/drf_htmx_renderer.git
cd drf_htmx_renderer
pip install -e .
pip install -r requirements-dev.txt
python manage.py runserver
Settings
Add these to Django settings.py
DRF_AUTO_METADATA_ADAPTER = 'htmx_renderer.adapters.HTMXEndpointAdapter'
DRF_AUTO_BASE_SERIALIZER = 'htmx_renderer.serializers.HTMXModelSerializer'
DRF_AUTO_BASE_VIEWSET = 'htmx_renderer.views.ModelViewSet'
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'htmx_renderer.renderers.TemplateHTMLRenderer',
'rest_framework.renderers.JSONRenderer',
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 50,
}
Add htmx_renderer in to INSTALLED_APPS:
INSTALLED_APPS = [
...
# API
'rest_framework',
'drf_auto_endpoint',
'htmx_renderer',
# TEMPLATES
'bootstrap5',
'mathfilters',
]
URLs
Add this to the main urls.py
from drf_auto_endpoint.router import router
urlpatterns = [
...
path('api/v1/', include(router.urls)),
...
]
Getting started
Create an endpoint for your model
Inside <your_app>/endpoints.py create an endpoint:
from drf_auto_endpoint.endpoints import Endpoint
from drf_auto_endpoint.router import register
from .models import MyModel
@register
class MyModelEndpoint(Endpoint):
model = MyModel
Restart Django's development serve and point it to http://localhost:8000/api/v1/
For further customization of your endpoint, refer to DRF-Schema-Adapter's documentation
Building
This project uses standardized pyproject.toml for the package. To build it simply invoke
python -m build
(note, you may need to install build package first).
To install package in development mode you can use
pip install -e .
Development
Sample (demo) app
One way to start the development is to run our demo app
and explore examples.
Source code is available in sample subdirectory.
Create migrations
python manage.py migrate
Start development server
python manage.py runserver
Metadata
Release files for drf-htmx-renderer 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf-htmx-renderer-0.0.2.tar.gz | 6.7 kB | Without provenance | Details for drf-htmx-renderer-0.0.2.tar.gz |
Release files / drf-htmx-renderer-0.0.2.tar.gz
| Download URL | drf-htmx-renderer-0.0.2.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b3c89b7b5109dfea15df0ab8596149e5aa187a9f1b534038005e00baebc459d
|
|
BLAKE2b-256 checksum How to use checksums |
bf9a961e5906a21b15a4bf9d0265b4d10a07713a1765a940e18f6e49db0ff095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for drf-htmx-renderer 0.0.2
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.