No project description provided
Project description
Django View Utils
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
Built Distribution
Hashes for django_view_decorator-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e489b92b5e856394c6f93c2d222c87c6fd776977b143571861d2b323bff0110 |
|
MD5 | a08cf974ec89a264793b673015ac918d |
|
BLAKE2b-256 | d5a6941d9aed0965442037aa86420ac339e7f43eb071f1ee73c4fb00363ad541 |
Hashes for django_view_decorator-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21bace04038a0f519761a38ec4be17a67e97d4da241a855f20a84d944008a131 |
|
MD5 | 8f3736c0fd0cb4f0b287ecad60f6ac99 |
|
BLAKE2b-256 | ac1186f3b66c9dd0d48072de73dd94564b70d00197df1d00d6fcd793d93fc1f6 |