Skip to main content

Django-Routify

Django-Routify is a lightweight package designed to simplify routing views in the classic Django framework.

With Django-Routify, you no longer need to manually register your views in urlpatterns using Django's path() function. Instead, the package introduces the Router class, allowing you to easily register views using the @Router.route(url_path=...) decorator. This approach is similar to what you might already be familiar with from frameworks like Flask, FastAPI, or Django REST Framework (DRF), where views are registered with decorators. This not only makes your code easier to read but also streamlines the process of routing.

Additionally, Django-Routify provides the option to set auto_trailing_slash=True when initializing the Router. This allows you to write URL paths similar to those in Flask or FastAPI, such as /hello-world, which will be automatically translated into the classic Django URL format: hello-world/.

Django-Routify supports both function-based and class-based views, as well as asynchronous views, providing flexibility for different project needs.

Documentation

Documentation are already available here!

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)


@router.route('/hello-world', methods=['GET']) # or @router.get('/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
from django.views.decorators.http import require_http_methods


@require_http_methods(['GET'])
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

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

Release files for django-routify 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-routify 0.3.4
File Size Uploaded
django_routify-0.3.4.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-routify 0.3.4
File Interpreter ABI Platform
django_routify-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / django_routify-0.3.4.tar.gz

Download URL django_routify-0.3.4.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
be0bb7f8479f0d14d1b186bf89c981c24b36fbdb556cf6abfdb4459ff6e2f510
BLAKE2b-256 checksum
How to use checksums
7be1ab014e8f23abc1d1b1cbb7d5bc2066ee3d81d9f7ca0fb15d4075ada9659e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / django_routify-0.3.4-py3-none-any.whl

Download URL django_routify-0.3.4-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
823cb7e1fb93e972fd56cf6d628ec404ff5a49060f232f2d55c9bdab4a35ffc4
BLAKE2b-256 checksum
How to use checksums
6229e50a79fc643897e7ce5e54857e5c07a0b70b20c42c790fd94646f8b6ac99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page