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/'.
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
Installation
To install Django-Routify package use the command below in your environment:
- For Linux/Mac:
python3 -m pip install django-routify
- For Windows:
python -m pip install django-routify
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.4.tar.gz
.
File metadata
- Download URL: django_routify-0.2.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a46af6a66f1cf5819471c7363cc51531654a0df39424bf1def63c678e195541b |
|
MD5 | 63a78790e4bb59e63ec13f771a05b997 |
|
BLAKE2b-256 | 8818a168070554637b8f4a203909f4c00e4331afb3fde9fb42945b7c172061a1 |
Provenance
File details
Details for the file django_routify-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: django_routify-0.2.4-py3-none-any.whl
- Upload date:
- Size: 6.5 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 | 94be3b08ea676385a7404da6c584fb280320044af839f399820604fe42bfa286 |
|
MD5 | 6682c07d846ff7d812e1ca4146c2c3c2 |
|
BLAKE2b-256 | bbb759f86d77bb345e712292f980d74ce409d262aff57b4d27b30473f7f90b7f |