mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Update to Django 2.0 Routing Syntax
Updated the code in tutorial part 6, "Using Routers", to Django 2.0 routing syntax using path().
This commit is contained in:
parent
7e0ad9262e
commit
cce3134e19
|
@ -3,7 +3,6 @@
|
||||||
REST framework includes an abstraction for dealing with `ViewSets`, that allows the developer to concentrate on modeling the state and interactions of the API, and leave the URL construction to be handled automatically, based on common conventions.
|
REST framework includes an abstraction for dealing with `ViewSets`, that allows the developer to concentrate on modeling the state and interactions of the API, and leave the URL construction to be handled automatically, based on common conventions.
|
||||||
|
|
||||||
`ViewSet` classes are almost the same thing as `View` classes, except that they provide operations such as `read`, or `update`, and not method handlers such as `get` or `put`.
|
`ViewSet` classes are almost the same thing as `View` classes, except that they provide operations such as `read`, or `update`, and not method handlers such as `get` or `put`.
|
||||||
|
|
||||||
A `ViewSet` class is only bound to a set of method handlers at the last moment, when it is instantiated into a set of views, typically by using a `Router` class which handles the complexities of defining the URL conf for you.
|
A `ViewSet` class is only bound to a set of method handlers at the last moment, when it is instantiated into a set of views, typically by using a `Router` class which handles the complexities of defining the URL conf for you.
|
||||||
|
|
||||||
## Refactoring to use ViewSets
|
## Refactoring to use ViewSets
|
||||||
|
@ -116,7 +115,7 @@ Here's our re-wired `snippets/urls.py` file.
|
||||||
|
|
||||||
# The API URLs are now determined automatically by the router.
|
# The API URLs are now determined automatically by the router.
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^', include(router.urls))
|
path('', include(router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
Registering the viewsets with the router is similar to providing a urlpattern. We include two arguments - the URL prefix for the views, and the viewset itself.
|
Registering the viewsets with the router is similar to providing a urlpattern. We include two arguments - the URL prefix for the views, and the viewset itself.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user