https://github.com/valberg/django-view-decorator
https://github.com/valberg/django-view-decorator
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/valberg/django-view-decorator
- Owner: valberg
- License: mit
- Created: 2023-03-25T10:43:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-10T20:44:55.000Z (9 months ago)
- Last Synced: 2025-02-10T21:33:33.552Z (9 months ago)
- Language: Python
- Size: 50.8 KB
- Stars: 46
- Watchers: 3
- Forks: 3
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- stars - valberg/django-view-decorator - (Python)
README
# Django View Decorator
[](https://github.com/valberg/django-view-decorator/actions/workflows/test.yml)
[](https://django-view-decorator.readthedocs.io/en/latest/?badge=latest)
[](https://results.pre-commit.ci/latest/github/valberg/django-view-decorator/main)
[](https://pypi.org/project/django-view-decorator)
[](https://pypi.org/project/django-view-decorator)
-----
**django-view-decorator** is decorator aimed at bringing locality of behaviour to the connection between a URL and a view in Django.
Read more about the motivation behind the package in a recent [blogpost](https://valberg.dk/bringing-locality-of-behaviour-to-django-views-and-urls.html).
**Table of Contents**
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)
## Installation
```console
pip install django-view-decorator
```
## Usage
Setup the project URLconf to include URLs from django-view-decorator:
```python
# project/urls.py (this is what we point the ROOT_URLCONF setting at)
from django.urls import path
from django_view_decorator import include_view_urls
urlpatterns = [
path("", include_view_urls()),
]
```
Use the decorator like so, for:
### Function-based views
```python
# foos/views.py
from django_view_decorator import view
@view(paths="/foo/", name="foo")
def foo(request: HttpRequest) -> HttpResponse:
return HttpResponse("foo")
```
### Class-based views
```python
@view(paths="/foo/", name="foo-list")
class FooList(ListView):
model = Foo
```
## Development
```console
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](https://spdx.org/licenses/MIT.html) license.