Skip to main content

No project description provided

Project description

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.

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

django_view_utils-0.0.4.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

django_view_utils-0.0.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

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

Hashes for django_view_utils-0.0.4.tar.gz
Algorithm Hash digest
SHA256 8b2d4e8a813653b9a06b71abf1a6d91943153074f9a44164a5c44d4e295241c1
MD5 f0e7612315054defe54efde00c8cc828
BLAKE2b-256 fc061292c9ab8c34f395addc2087466a6a2abda2c325f03345e6c21a4a4c3cef

See more details on using hashes here.

File details

Details for the file django_view_utils-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_view_utils-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 339cb3c97a6a70b2d5d512b85e5c64a1b5f787a241e521099405647b88d7903e
MD5 3b6e84f998f67de3396da68c7fb177e3
BLAKE2b-256 e2486439358ccade1c4647e74618229eaa6d9563f73e713a5c6fc4f2651a4254

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page