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

Uploaded Source

Built Distribution

django_routify-0.2.7.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_routify-0.2.7.1.tar.gz
  • Upload date:
  • Size: 6.9 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.7.1.tar.gz
Algorithm Hash digest
SHA256 a59dcec099784b68a5a040204b318a551a8c53b002152bc0545582b729200a7e
MD5 98a95f04e02a72ba3adfa7e8b3bcd009
BLAKE2b-256 46b0ed730404dae8f9c144710c750f5ded4bdff3ecd62750b734c6e6e8903787

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for django_routify-0.2.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 676288566fe94be6ceed7dbebdcef36c87edd067b3e68ae2fcc21c47ff132595
MD5 2fe7c59964ed563d36669a8d1aca50db
BLAKE2b-256 3bb25c45bcb976d6b3e68942a2ad86c22c8eb0064f7f8508f01240024d699f44

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