Skip to main content

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 don't have anymore manually register your views in urlpatterns using django.urls.path function.

Django-Routify can help you to easy 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 things

Instalation

To install Django-Routify package use command below in your environment:

  • For Linux/Mac:
python3 -m pip install django-routify
  • For Windows:
python -m pip install django-routify

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_routify-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

django_routify-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file django_routify-0.2.0.tar.gz.

File metadata

  • Download URL: django_routify-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for django_routify-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2e2447fb8179df3309e32aba1f5925cd9a247cf6807dd8c55ce2b23d5a7797b5
MD5 935177d618e83a14949133a7292fcdac
BLAKE2b-256 a7f062a45722998cb12148665fd1406baf256bb85a8a5a5948b2910f2e7836e1

See more details on using hashes here.

Provenance

File details

Details for the file django_routify-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_routify-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41e34908a0571344012d78d0bed7d491c0fb75d01f82b0de320267c8f995d15a
MD5 3ee23f9f2f8777d3202078d88d17d1e3
BLAKE2b-256 93a770b30e272282a09c612870b934a44ceff0cf72e68dcbf640de4c5947e485

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page