You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Allow usage of Django 2.x path in SimpleRouter
* Use path in Default router
* Update docs/api-guide/routers.md
Co-authored-by: Éric <[email protected]>
* Update docs/api-guide/routers.md
Co-authored-by: Éric <[email protected]>
* Add tests also for default router with path
* Use a more relevant attribute for lookup when using path converters
Co-authored-by: Asif Saif Uddin <[email protected]>
Co-authored-by: Éric <[email protected]>
Copy file name to clipboardExpand all lines: docs/api-guide/routers.md
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -167,12 +167,23 @@ This behavior can be modified by setting the `trailing_slash` argument to `False
167
167
168
168
Trailing slashes are conventional in Django, but are not used by default in some other frameworks such as Rails. Which style you choose to use is largely a matter of preference, although some javascript frameworks may expect a particular routing style.
169
169
170
-
The router will match lookup values containing any characters except slashes and period characters. For a more restrictive (or lenient) lookup pattern, set the `lookup_value_regex` attribute on the viewset. For example, you can limit the lookup to valid UUIDs:
170
+
By default the URLs created by `SimpleRouter` use regular expressions. This behavior can be modified by setting the `use_regex_path` argument to `False` when instantiating the router, in this case [path converters][path-converters-topic-reference] are used. For example:
171
+
172
+
router = SimpleRouter(use_regex_path=False)
173
+
174
+
**Note**: `use_regex_path=False` only works with Django 2.x or above, since this feature was introduced in 2.0.0. See [release note][simplified-routing-release-note]
175
+
176
+
177
+
The router will match lookup values containing any characters except slashes and period characters. For a more restrictive (or lenient) lookup pattern, set the `lookup_value_regex` attribute on the viewset or `lookup_value_converter` if using path converters. For example, you can limit the lookup to valid UUIDs:
171
178
172
179
class MyModelViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
173
180
lookup_field = 'my_model_id'
174
181
lookup_value_regex = '[0-9a-f]{32}'
175
182
183
+
class MyPathModelViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
184
+
lookup_field = 'my_model_uuid'
185
+
lookup_value_converter = 'uuid'
186
+
176
187
## DefaultRouter
177
188
178
189
This router is similar to `SimpleRouter` as above, but additionally includes a default API root view, that returns a response containing hyperlinks to all the list views. It also generates routes for optional `.json` style format suffixes.
@@ -340,3 +351,5 @@ The [`DRF-extensions` package][drf-extensions] provides [routers][drf-extensions
0 commit comments