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', methods=['GET'])
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

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

Uploaded Source

Built Distribution

django_routify-0.2.8-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_routify-0.2.8.tar.gz
  • Upload date:
  • Size: 7.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.8.tar.gz
Algorithm Hash digest
SHA256 63ec8b2c8e73af2515effe82ff9a454ddda656acb86fc497ec7b8ee5d146c37b
MD5 efdb4783364a8cd0904033514d9e88b0
BLAKE2b-256 e42f7dce923639748c2b51ae44e996a09f507536d7bb287125389ddb93f6fa6c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for django_routify-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7b27a5d35a4ac2aaa96e0c190a894e8817e0c906420310de04da334f8f921614
MD5 e4963beb52dd396506d305e9d2f55650
BLAKE2b-256 141b6209b0a4489cf3ebfa4edbec4701a753f961a2f1d1b39c9cb51377a25acd

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