update docs to use re_path() instead of url(r...

This commit is contained in:
Basil Begonia 2019-03-29 21:29:30 +08:00
parent f34a0a4e6a
commit 8a259a84fd
14 changed files with 31 additions and 31 deletions

View File

@ -113,8 +113,8 @@ router.register(r'users', UserViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
re_path(r'^', include(router.urls)),
re_path(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
```

View File

@ -196,7 +196,7 @@ When using `TokenAuthentication`, you may want to provide a mechanism for client
from rest_framework.authtoken import views
urlpatterns += [
url(r'^api-token-auth/', views.obtain_auth_token)
re_path(r'^api-token-auth/', views.obtain_auth_token)
]
Note that the URL part of the pattern can be whatever you want to use.
@ -235,7 +235,7 @@ For example, you may return additional user information beyond the `token` value
And in your `urls.py`:
urlpatterns += [
url(r'^api-token-auth/', CustomAuthToken.as_view())
re_path(r'^api-token-auth/', CustomAuthToken.as_view())
]

View File

@ -29,9 +29,9 @@ Example:
from blog import views
urlpatterns = [
url(r'^/$', views.apt_root),
url(r'^comments/$', views.comment_list),
url(r'^comments/(?P<pk>[0-9]+)/$', views.comment_detail)
re_path(r'^/$', views.apt_root),
re_path(r'^comments/$', views.comment_list),
re_path(r'^comments/(?P<pk>[0-9]+)/$', views.comment_detail)
]
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])

View File

@ -42,7 +42,7 @@ For more complex cases you might also want to override various methods on the vi
For very simple cases you might want to pass through any class attributes using the `.as_view()` method. For example, your URLconf might include something like the following entry:
url(r'^/users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
re_path(r'^/users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
---

View File

@ -122,7 +122,7 @@ If it is called without a `filename` URL keyword argument, then the client must
# urls.py
urlpatterns = [
# ...
url(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view())
re_path(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view())
]
---

View File

@ -60,7 +60,7 @@ For example, you can append `router.urls` to a list of existing views...
router.register(r'accounts', AccountViewSet)
urlpatterns = [
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
re_path(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
]
urlpatterns += router.urls
@ -68,22 +68,22 @@ For example, you can append `router.urls` to a list of existing views...
Alternatively you can use Django's `include` function, like so...
urlpatterns = [
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
url(r'^', include(router.urls)),
re_path(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
re_path(r'^', include(router.urls)),
]
You may use `include` with an application namespace:
urlpatterns = [
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
url(r'^api/', include((router.urls, 'app_name'))),
re_path(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
re_path(r'^api/', include((router.urls, 'app_name'))),
]
Or both an application and instance namespace:
urlpatterns = [
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
url(r'^api/', include((router.urls, 'app_name'), namespace='instance_name')),
re_path(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
re_path(r'^api/', include((router.urls, 'app_name'), namespace='instance_name')),
]
See Django's [URL namespaces docs][url-namespace-docs] and the [`include` API reference][include-api-reference] for more details.

View File

@ -358,7 +358,7 @@ List of url patterns to limit the schema introspection to. If you only want the
to be exposed in the schema:
schema_url_patterns = [
url(r'^api/', include('myproject.api.urls')),
re_path(r'^api/', include('myproject.api.urls')),
]
schema_view = get_schema_view(

View File

@ -155,14 +155,14 @@ In the following example we're giving a set of views two different possible URL
# bookings/urls.py
urlpatterns = [
url(r'^$', bookings_list, name='bookings-list'),
url(r'^(?P<pk>[0-9]+)/$', bookings_detail, name='bookings-detail')
re_path(r'^$', bookings_list, name='bookings-list'),
re_path(r'^(?P<pk>[0-9]+)/$', bookings_detail, name='bookings-detail')
]
# urls.py
urlpatterns = [
url(r'^v1/bookings/', include('bookings.urls', namespace='v1')),
url(r'^v2/bookings/', include('bookings.urls', namespace='v2'))
re_path(r'^v1/bookings/', include('bookings.urls', namespace='v1')),
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.

View File

@ -69,7 +69,7 @@ schema_view = get_schema_view(
)
urlpatterns = [
url(r'^swagger/$', schema_view),
re_path(r'^swagger/$', schema_view),
...
]
```
@ -199,7 +199,7 @@ Make sure to include the view before your router urls. For example:
urlpatterns = [
url('^$', schema_view),
url(r'^', include(router.urls)),
re_path(r'^', include(router.urls)),
]
### Schema path representations

View File

@ -73,7 +73,7 @@ To install the API documentation, you'll need to include it in your projects URL
urlpatterns = [
...
url(r'^docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
re_path(r'^docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
]
Once installed you should see something a little like this:

View File

@ -121,7 +121,7 @@ If you're intending to use the browsable API you'll probably also want to add RE
urlpatterns = [
...
url(r'^api-auth/', include('rest_framework.urls'))
re_path(r'^api-auth/', include('rest_framework.urls'))
]
Note that the URL path can be whatever you want.
@ -169,8 +169,8 @@ Here's our project's root `urls.py` module:
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
re_path(r'^', include(router.urls)),
re_path(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
You can now open the API in your browser at [http://127.0.0.1:8000/](http://127.0.0.1:8000/), and view your new 'users' API. If you use the login control in the top right corner you'll also be able to add, create and delete users from the system.

View File

@ -384,7 +384,7 @@ First, install the API documentation views. These will include the schema resour
urlpatterns = [
...
url(r'^docs/', include_docs_urls(title='My API service'))
re_path(r'^docs/', include_docs_urls(title='My API service'))
]
Once the API documentation URLs are installed, you'll be able to include both the required JavaScript resources. Note that the ordering of these two lines is important, as the schema loading requires CoreAPI to already be installed.

View File

@ -26,7 +26,7 @@ To install the API documentation, you'll need to include it in your project's UR
urlpatterns = [
...
url(r'^docs/', include_docs_urls(title='My API title'))
re_path(r'^docs/', include_docs_urls(title='My API title'))
]
This will include two different views:
@ -48,7 +48,7 @@ You may ensure views are given a `request` instance by calling `include_docs_url
urlpatterns = [
...
# Generate schema with valid `request` instance:
url(r'^docs/', include_docs_urls(title='My API title', public=False))
re_path(r'^docs/', include_docs_urls(title='My API title', public=False))
]

View File

@ -48,7 +48,7 @@ being applied unexpectedly?</p>
when including the docs urls:</p>
<pre>
url(r'^docs/', include_docs_urls(title='Your API',
re_path(r'^docs/', include_docs_urls(title='Your API',
authentication_classes=[],
permission_classes=[])),
</pre>