A lightweight Django ViewSet alternative with minimal abstraction.
Project description
Django Small View Set
A lightweight Django ViewSet alternative with minimal abstraction. This library provides a simple and transparent way to define API endpoints without relying on complex abstractions.
Getting Started with Django Small View Set
This guide provides a simple example to get started with the library.
Example Usage
Here’s how you can define a basic API endpoint with one collection route and one detail route:
from django.http import JsonResponse
from django.urls import path
from small_view_set.small_view_set import SmallViewSet
from small_view_set.decorators import default_handle_endpoint_exceptions
class BarViewSet(SmallViewSet):
def urlpatterns(self):
return [
path('api/bars/', self.default_router, name='bars_collection'),
path('api/bars/<int:pk>/', self.default_router, name='bars_detail'),
]
@default_handle_endpoint_exceptions
def list(self, request, *args, **kwargs):
self.protect_list(request)
return JsonResponse({"message": "Hello, world!"}, status=200)
@default_handle_endpoint_exceptions
def retrieve(self, request, pk, *args, **kwargs):
self.protect_retrieve(request)
return JsonResponse({"message": f"Detail for ID {pk}"}, status=200)
Registering in urls.py
To register the viewset in your urls.py:
from api.views.bar import BarViewSet
urlpatterns = [
# Other URLs like admin, static, etc.
*BarViewSet().urlpatterns(),
]
Documentation
- Custom Endpoints: Learn how to define custom endpoints alongside the default router.
- Handling Endpoint Exceptions: Understand how to write your own decorators for exception handling.
- Custom Protections: Learn how to subclass
SmallViewSetto add custom protections like logged-in checks. - DRF Compatibility: Learn how to use some of Django Rest Framework's tools, like Serializers.
- Reason: Reasoning behind this package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_small_view_set-0.1.3.tar.gz.
File metadata
- Download URL: django_small_view_set-0.1.3.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.8.0-58-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef4362c154a93f828bd0e075baa383ef724be4a182cabae99868b4b58c93daca
|
|
| MD5 |
92e93bd067a4f6c464dfa3231ad81556
|
|
| BLAKE2b-256 |
d7fb9123f443f773ca60d26056eb76c79b1f4b0289fd82888a07144567ef0887
|
File details
Details for the file django_small_view_set-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_small_view_set-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.8.0-58-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d7857041f78740f78430ae9d96e8e39f8355c8a1245d4666440d108f1b12692
|
|
| MD5 |
372a518014fe67a8bfdb5ab1e00e046d
|
|
| BLAKE2b-256 |
cc81eee09e7e5b3e3a20de8f9a1d2b317e29746ca87f6b9c05b0515ae90a74ea
|