mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-25 16:00:49 +03:00
Updated url() with re_path() in Versioning docs. (#7043)
This commit is contained in:
parent
0d3d548aa5
commit
0d6589cf45
|
@ -132,12 +132,12 @@ This scheme requires the client to specify the version as part of the URL path.
|
||||||
Your URL conf must include a pattern that matches the version with a `'version'` keyword argument, so that this information is available to the versioning scheme.
|
Your URL conf must include a pattern that matches the version with a `'version'` keyword argument, so that this information is available to the versioning scheme.
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(
|
re_path(
|
||||||
r'^(?P<version>(v1|v2))/bookings/$',
|
r'^(?P<version>(v1|v2))/bookings/$',
|
||||||
bookings_list,
|
bookings_list,
|
||||||
name='bookings-list'
|
name='bookings-list'
|
||||||
),
|
),
|
||||||
url(
|
re_path(
|
||||||
r'^(?P<version>(v1|v2))/bookings/(?P<pk>[0-9]+)/$',
|
r'^(?P<version>(v1|v2))/bookings/(?P<pk>[0-9]+)/$',
|
||||||
bookings_detail,
|
bookings_detail,
|
||||||
name='bookings-detail'
|
name='bookings-detail'
|
||||||
|
@ -158,14 +158,14 @@ In the following example we're giving a set of views two different possible URL
|
||||||
|
|
||||||
# bookings/urls.py
|
# bookings/urls.py
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', bookings_list, name='bookings-list'),
|
re_path(r'^$', bookings_list, name='bookings-list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/$', bookings_detail, name='bookings-detail')
|
re_path(r'^(?P<pk>[0-9]+)/$', bookings_detail, name='bookings-detail')
|
||||||
]
|
]
|
||||||
|
|
||||||
# urls.py
|
# urls.py
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^v1/bookings/', include('bookings.urls', namespace='v1')),
|
re_path(r'^v1/bookings/', include('bookings.urls', namespace='v1')),
|
||||||
url(r'^v2/bookings/', include('bookings.urls', namespace='v2'))
|
re_path(r'^v2/bookings/', include('bookings.urls', namespace='v2'))
|
||||||
]
|
]
|
||||||
|
|
||||||
Both `URLPathVersioning` and `NamespaceVersioning` are reasonable if you just need a simple versioning scheme. The `URLPathVersioning` approach might be better suitable for small ad-hoc projects, and the `NamespaceVersioning` is probably easier to manage for larger projects.
|
Both `URLPathVersioning` and `NamespaceVersioning` are reasonable if you just need a simple versioning scheme. The `URLPathVersioning` approach might be better suitable for small ad-hoc projects, and the `NamespaceVersioning` is probably easier to manage for larger projects.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user