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 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


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.5.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

django_routify-0.2.5-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_routify-0.2.5.tar.gz
  • Upload date:
  • Size: 5.8 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.5.tar.gz
Algorithm Hash digest
SHA256 609a3c6dce0712f606b4bdbc5198d9afaacb1cf931a8bbcc62331258b191d0b2
MD5 6fbc96f1362abf73bed4771510398251
BLAKE2b-256 3f4f88d70f42145d9200fd29e7ad6c1c49fa7e8767e83b487fa28e1edb3bf75d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for django_routify-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dd4529b4d4ab03a50223f503eb9b941fc355d31c7b771b37e6a830253736b7dd
MD5 be57ac2b7e4750e4b631d45f2d01a59b
BLAKE2b-256 511078c5ee28af876f46c1082917c3981069f2e2e9b2a3ca8079c8729d603414

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