A flask-style route decorator for django views
Simple things should be simple, complex things should be possible (c)Alan Kay
There is some contradiction between decoupling and DRY principles
in django urls. Why not use flasky @route decorator to fix this issue?
Install
pip install django-route-decorator
It's compatible with django >= 2.0 only,
because it uses new urls.path syntax.
Simple things should be simple
Just decorate your views with an instance of Route:
from route_decorator import Route
route = Route()
@route
def foo_view(request):
# /foo-view
@route
def bar__view(request):
# double underscore means a folder
# /bar/view
And don't forget to add the routes into your urls.py:
from . import views
urlpatterns += views.route.patterns
Now you have your views binded to /foo-view and /bar-view respectively.
You can also get map urlname -> url with route.names and pass them to
frontend maybe. In our case it would be:
{
'foo_view': '/foo-view',
'bar__view': '/bar/view'
}
Complex things should be possible
You can pass url_prefix and name_prefix to route:
route = Router('/api', 'api:')
And also use path and name in a decorator:
@route('/baz', 'baz-name')
def baz_view(request):
...
So it would be bind to /api/baz with name api:baz-name.
Metadata
Release files for django-route-decorator 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_route_decorator-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_route_decorator-0.1.1-py3-none-any.whl |
Release files / django_route_decorator-0.1.1-py3-none-any.whl
| Download URL | django_route_decorator-0.1.1-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c2e8a67ae5bc78699ce0f48b05278062d559aeabe918520a408bb1a5eaebdea
|
|
BLAKE2b-256 checksum How to use checksums |
55fadcc120ac8fa3c5501b4fa7e3d2accecc5e501118c355e698e424785c689a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
|
Security for django-route-decorator 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.