Django-Routify is a package for simple routing Views in the classic Django framework.
Project description
Django-Routify
Django-Routify is a package for simple routing Views in the classic Django framework.
With Django-Routify package you no longer have to manually register your views in urlpatterns
using django.urls.path function.
Django-Routify can help you to easily register your views using Router class and his @Router.route(...) decorator. If you are familiar with Flask, FastAPI or even Django REST Framework, you know that every single view should be registered using decorators. It is easy to read first of all, and simplified work.
Also you can set auto_trailing_slash
to True
value when you're initializing your Router and can write your url_path similar to Flask, FastAPI etc.
If auto_trailing_slash
is True
then url_path which will be equal to '/hello-world'
will be translated to classic Django url rule - 'hello-world/'
.
Django-Routify is support function
and class
based views, and also asynchronous
.
Requirements
- Python 3.8+
- Django 4.0+
Installation
To install Django-Routify package use the command below in your environment:
- Using
pip
pip install django-routify
- Using
Poetry
poetry add django-routify
Example
For extended example with tests visit examples/example.
Using Django-Routify with Django
~/project/app/views.py:
from django.http import HttpRequest, HttpResponse
from django_routify import Router
router = Router('/app', 'app', auto_trailing_slash=True)
# or = Router(prefix='/app', app_name='app', auto_trailing_slash=True)
@router.route('/hello-world')
def hello_world(request: HttpRequest) -> HttpResponse:
return HttpResponse('Hello World!')
~/project/app/urls.py:
from django_routify import include_router
from .views import router
urlpatterns = [
include_router(router),
]
Using classic Django
~/project/app/views.py:
from django.http import HttpRequest, HttpResponse
def hello_world(request: HttpRequest) -> HttpResponse:
return HttpResponse('Hello World!')
~/project/app/urls.py:
from django.urls import path, include
from .views import hello_world
app_name = 'app'
urlpatterns = [
path(
'app/',
include([
path('hello-world/', hello_world, name='hello_world'),
])
),
]
Note:
The result of these two examples will do the same thing
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_routify-0.2.7.tar.gz
.
File metadata
- Download URL: django_routify-0.2.7.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9073cc2c47c751f915deda1f8eef2a1bcc811a2e767d563e323c936df0b46d1 |
|
MD5 | 6e017d9964acafdcc26e28b9b3421f17 |
|
BLAKE2b-256 | be9b0d754297bfeb58a9ec7306de23ba9f1d83b6c81ff0a0b4fdd09c5ce2672b |
Provenance
File details
Details for the file django_routify-0.2.7-py3-none-any.whl
.
File metadata
- Download URL: django_routify-0.2.7-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac65fc1b79b634238e420b9ca8ee4da9582266a45fc56d68c562b4773916546c |
|
MD5 | 6166138a07af02162e73a10fbf2c440c |
|
BLAKE2b-256 | 15868e02e3ea4166c6ba8e23940a4d6cc53eca2e838aa3c14787db0d3d0b4d19 |