Skip to main content

Django View Utils

Tests Documentation PyPI - Version PyPI - Python Version


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.

Metadata

Release files for django-view-utils 0.0.4

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-view-utils 0.0.4
File Size Uploaded Provenance Actions
django_view_utils-0.0.4.tar.gz 4.9 kB Without provenance Details for django_view_utils-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-view-utils 0.0.4
File Interpreter ABI Platform Actions
django_view_utils-0.0.4-py3-none-any.whl Python 3 none any Details for django_view_utils-0.0.4-py3-none-any.whl

Total release size: 11.5 kB

Release files / django_view_utils-0.0.4.tar.gz

Download URL django_view_utils-0.0.4.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8b2d4e8a813653b9a06b71abf1a6d91943153074f9a44164a5c44d4e295241c1
BLAKE2b-256 checksum
How to use checksums
fc061292c9ab8c34f395addc2087466a6a2abda2c325f03345e6c21a4a4c3cef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release files / django_view_utils-0.0.4-py3-none-any.whl

Download URL django_view_utils-0.0.4-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
339cb3c97a6a70b2d5d512b85e5c64a1b5f787a241e521099405647b88d7903e
BLAKE2b-256 checksum
How to use checksums
e2486439358ccade1c4647e74618229eaa6d9563f73e713a5c6fc4f2651a4254
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Security for django-view-utils 0.0.4

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