Skip to main content

No project description provided

Project description

Django View Utils

Tests Documentation PyPI - Version PyPI - Python Version pre-commit.ci status


django-view-decorator aims to be a collection of (opinionated) 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_decorator import view, include_view_urls


@view(paths="/hello-world/", name="hello-world")
def my_view(request):
    ...


# <app>/urls.py

from django.urls import path

urlpatterns = [
    path("", include_view_urls()),
]

By default, django-view-decorator 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-decorator

Development

git clone
cd django-view-decorator
pip install hatch
hatch run tests:cov
hatch run tests:typecheck

License

django-view-decorator 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_decorator-0.0.1.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

django_view_decorator-0.0.1-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

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