Giter Site home page Giter Site logo

django-view-decorator's Introduction

Django View Decorator

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


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.

Table of Contents

Installation

pip install django-view-decorator

Usage

Setup the project URLconf to include URLs from django-view-decorator:

# 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

# 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

@view(paths="/foo/", name="foo-list")
class FooList(ListView):
    model = Foo

Parameters

  • paths: is in a plural form because support also a list of paths
  • name the classic route name
  • namespace: {I don't know what to write here}
  • extra_modules: the python module itselfs (require a list)
  • extra_packages: can be a real path (require a list)
  • login_required: so you can avoid the Django decorator
  • permission_required: so you can avoid the Django decorator

extra_packages example for real paths

import os
# We need the project directory
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
urlpatterns = [
    path("", include_view_urls(extra_modules=[root + "/portal/views"])),
]

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.

django-view-decorator's People

Contributors

jkaeske avatar mte90 avatar pre-commit-ci[bot] avatar valberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.