ITADN

Add `Router.to_urlpatterns` method

#1262Opensobolevn 创建于 15 天前
featuregood first issuehelp wanted
S
sobolevncommented
The main idea is that we can refactor this: ```python >>> from django.urls import include, path >>> from dmr.routing import Router >>> router = Router( ... 'api/', ... [ ... path('user/', UserController.as_view(), name='users'), ... ], ... ) >>> urlpatterns = [ ... path(router.prefix, include((router.urls, 'my_app'), namespace='api')), ... ] ``` into this: ```python >>> from django.urls import include, path >>> from dmr.routing import Router >>> router = Router( ... 'api/', ... [ ... path('user/', UserController.as_view(), name='users'), ... ], ... ) >>> urlpatterns = [ ... path(*router.to_urlpatterns(namespace='api')), ... ] ``` It should return `tuple` of `(prefix, urlpatterns)` properly typed. It also should be a default way in the docs. You would also need to update `routing.rst` docs to show that these two operations are basically the same. See how we do it with `Router.include` in the same file.
0 条评论