Include Django URL patterns with decorators
Project description
Include Django URL patterns with decorators.
Maintained by Stéphane “Twidi” Angel, and Jon Dufresne on https://github.com/twidi/django-decorator-include based on the original work from Jeff Kistler on https://github.com/jeffkistler/django-decorator-include.
Installation
Assuming you have pip installed, run the following command to install from PyPI:
pip install django-decorator-include
Usage
decorator_include is intended for use in URL confs as a replacement for the django.conf.urls.include function. It works in almost the same way as include however the first argument should be either a decorator or an iterable of decorators to apply to all included views (if an iterable, the order of the decorators is the order in which the functions will be applied on the views). Herei s an example URL conf:
from django.contrib import admin from django.core.exceptions import PermissionDenied from django.urls import path from django.contrib.auth.decorators import login_required, user_passes_test from decorator_include import decorator_include from mysite.views import index def only_user(username): def check(user): if user.is_authenticated and user.username == username: return True raise PermissionDenied return user_passes_test(check) urlpatterns = [ path('', views.index, name='index'), # will redirect to login page if not authenticated path('secret/', decorator_include(login_required, 'mysite.secret.urls')), # will redirect to login page if not authenticated # will return a 403 http error if the user does not have the "god" username path('admin/', decorator_include([login_required, only_user('god')], admin.site.urls), ]
Supported versions
Django versions |
Python versions |
---|---|
2.0 |
3.4, 3.5, 3.6, 3.7 |
2.1 |
3.5, 3.6, 3.7 |
2.2 |
3.5, 3.6, 3.7, 3.8 |
3.0 |
3.6, 3.7, 3.8 |
All library versions to use for old Django/Python support
Django versions |
Python versions |
Library versions |
---|---|---|
1.4, 1.5 |
2.6, 2.7 |
1.2 |
1.6 |
2.6, 2.7, 3.2, 3.3 |
1.2 |
1.7 |
2.7, 3.2, 3.3, 3.4 |
1.2 |
1.8 |
2.7, 3.2, 3.3, 3.4, 3.5 |
1.3 |
1.9, 1.10 |
2.7, 3.4, 3.5 |
1.3 |
1.11 |
2.7, 3.4, 3.5, 3.6 |
1.4.x (>=1.4.1,<2) |
2.0 |
3.4, 3.5, 3.6, 3.7 |
3.0 |
2.1 |
3.5, 3.6, 3.7 |
3.0 |
2.2 |
3.5, 3.6, 3.7, 3.8 |
3.0 |
3.0 |
3.6, 3.7, 3.8 |
3.0 |
Development
Make sure you are in a virtualenv on a valid python version.
Grab the sources from Github:
git clone -b develop https://github.com/twidi/django-decorator-include.git
Then go into the newly created django-decorator-include directory and install the few needed libraries:
pip install -r requirements.txt
To run the tests, this library provides a test project, so you can launch them this way:
django-admin test --settings=tests.settings tests
Or simply launch the runtests.sh script (it will run this exact command):
./runtests.sh
Base your work on the develop branch. Iit should be the default branch on git assuming you used the -b develop argument on the git clone command as shown above.
When creating the pull request, ensure you are using the correct base (twidi/django-decorator-include on develop).
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file django-decorator-include-3.0.tar.gz
.
File metadata
- Download URL: django-decorator-include-3.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18db98e0e48dbb3977ab79b5520dbf5ecbb35f0bced8e15ed62dc66762345856 |
|
MD5 | 03ed2c866dce7bf1161fb9ea0778be22 |
|
BLAKE2b-256 | 4d11d13f07b11b37c7f0a4860e37c2f93387f83343e82376313a22f9dd3bda0c |
Provenance
File details
Details for the file django_decorator_include-3.0-py3-none-any.whl
.
File metadata
- Download URL: django_decorator_include-3.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe7a96afb23f66dcbc6227d3c48430e53cc5704eab30841ddb8bd940e5ea8a5a |
|
MD5 | dbb4d8936980517048224548739169b3 |
|
BLAKE2b-256 | f7a9d8e41e2b4dc42ae59a28e4f680909bee9831a848495679d5c1b46b5c1a8e |