No project description provided
Project description
Django View Utils
django-view-utils aims to be a collection of useful utilities for Django views. Mainly function based views.
Features
@view decorator
The @view decorator is a simple way to create a view function and register it with a URL.
# <app>/views.url
from django_view_utils import view
@view(paths="/hello-world/", name="hello-world")
def my_view(request):
...
# <app>/urls.py
from django.urls import path
from django_view_utils import include_view_urls
urlpatterns = [
path("", include_view_urls()),
]
By default, django-view-utils will look for a views.py file in your app.
This can be disabled by setting DJANGO_VIEW_UTILS_AUTO_DISCOVER to False, then registering view modules is up to you by supplying the modules keyword argument to include_view_urls.
@view decorator options
Conveniently it also supports login_required, staff_required and permission_required.
@view(paths="/hello-world/", name="hello-world", login_required=True)
def my_view(request):
...
@view(paths="/hello-world/", name="hello-world", staff_required=True)
def my_view(request):
...
@view(paths="/hello-world/", name="hello-world", permissions=["myapp.can_do_something"])
def my_view(request):
...
Inspiration
This decorator is very much inspired by the idea of "locality of behaviour" by Carson Gross (creator of HTMX): https://htmx.org/essays/locality-of-behaviour/.
It also bears resemblance to the @app.route decorator in Flask, the @app.<HTTP method> decorator in FastAPI and probably many other Python web frameworks.
Table of Contents
Installation
pip install django-view-utils
Development
git clone
cd django-view-utils
pip install hatch
hatch run tests:cov
hatch run tests:typecheck
License
django-view-utils is distributed under the terms of the MIT license.
Project details
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_view_utils-0.0.4.tar.gz.
File metadata
- Download URL: django_view_utils-0.0.4.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b2d4e8a813653b9a06b71abf1a6d91943153074f9a44164a5c44d4e295241c1
|
|
| MD5 |
f0e7612315054defe54efde00c8cc828
|
|
| BLAKE2b-256 |
fc061292c9ab8c34f395addc2087466a6a2abda2c325f03345e6c21a4a4c3cef
|
File details
Details for the file django_view_utils-0.0.4-py3-none-any.whl.
File metadata
- Download URL: django_view_utils-0.0.4-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
339cb3c97a6a70b2d5d512b85e5c64a1b5f787a241e521099405647b88d7903e
|
|
| MD5 |
3b6e84f998f67de3396da68c7fb177e3
|
|
| BLAKE2b-256 |
e2486439358ccade1c4647e74618229eaa6d9563f73e713a5c6fc4f2651a4254
|