Documentation

# Router


Router class is intended for future registration of views including basic settings, such as prefix, app_name etc. Class works great with Django-Routify v0.2.7.1 and above.


Router initializer has the following parameters:


# Router decorators


Router has following decorators:


Decorator @router.route has the following parameters:


Decorators @router.get, @router.post, @router.put, @router.patch and @router.delete for single HTTP method wrapping has the following parameters:


# Including router function


For including router into urlpatterns Django-Routify has function called include_router which is getting router instance as a parameter.


# Dynamic URL patterns


In new v0.3.3 has been added custom dynamic patterns which can be setted during Router initializing in dynamic_pattern parameter.

It can be useful for those people which is familiar with dynamic URL patterns from Go, NodeJS, PHP etc.

Patterns are automatically getting types from annotations, or from 'parameters' attribute (example: {'book': str}) of class. By default if Pattern didn't found annotation of type it will be automatically setted to slug django type.


Django-Routify has the following dynamic URL pattern classes:


Example of usage custom patterns:

from django.views.generic import TemplateView

from django_routify import Router, CurlyPattern

router = Router(prefix='/users', dynamic_pattern=CurlyPattern)


@router.get('/{user_id}') # will be translated to '/<int:user_id>'
class User(TemplateView):
    parameters = {
        'user_id': int, # annotation for user_id
    }
    template_name = 'user.html'


print(router)
'''
Router(
    app_name:   ""
    url_prefix: "users"
    urls:       [<URLPattern '/<int:user_id>' [name='user']>]
)
'''
Star it