diff --git a/README.md b/README.md index 66079edf0..2c3142560 100644 --- a/README.md +++ b/README.md @@ -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')) ] ``` diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md index 5b8a9844f..d4f6279ba 100644 --- a/docs/api-guide/authentication.md +++ b/docs/api-guide/authentication.md @@ -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()) ] diff --git a/docs/api-guide/format-suffixes.md b/docs/api-guide/format-suffixes.md index 629f003f3..6f83f90fc 100644 --- a/docs/api-guide/format-suffixes.md +++ b/docs/api-guide/format-suffixes.md @@ -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[0-9]+)/$', views.comment_detail) + re_path(r'^/$', views.apt_root), + re_path(r'^comments/$', views.comment_list), + re_path(r'^comments/(?P[0-9]+)/$', views.comment_detail) ] urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html']) diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index a0ed7bdea..2a0151807 100644 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -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') --- diff --git a/docs/api-guide/parsers.md b/docs/api-guide/parsers.md index be48ae7e5..c8095190c 100644 --- a/docs/api-guide/parsers.md +++ b/docs/api-guide/parsers.md @@ -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[^/]+)$', FileUploadView.as_view()) + re_path(r'^upload/(?P[^/]+)$', FileUploadView.as_view()) ] --- diff --git a/docs/api-guide/routers.md b/docs/api-guide/routers.md index 09c6c39cb..ecece5491 100644 --- a/docs/api-guide/routers.md +++ b/docs/api-guide/routers.md @@ -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. diff --git a/docs/api-guide/schemas.md b/docs/api-guide/schemas.md index b09b1606e..d3f009d90 100644 --- a/docs/api-guide/schemas.md +++ b/docs/api-guide/schemas.md @@ -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( diff --git a/docs/api-guide/versioning.md b/docs/api-guide/versioning.md index c106e536d..07568e4a6 100644 --- a/docs/api-guide/versioning.md +++ b/docs/api-guide/versioning.md @@ -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[0-9]+)/$', bookings_detail, name='bookings-detail') + re_path(r'^$', bookings_list, name='bookings-list'), + re_path(r'^(?P[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. diff --git a/docs/community/3.5-announcement.md b/docs/community/3.5-announcement.md index cce2dd050..6ca738e62 100644 --- a/docs/community/3.5-announcement.md +++ b/docs/community/3.5-announcement.md @@ -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 diff --git a/docs/community/3.6-announcement.md b/docs/community/3.6-announcement.md index c6e8dfa06..a6fd7492b 100644 --- a/docs/community/3.6-announcement.md +++ b/docs/community/3.6-announcement.md @@ -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: diff --git a/docs/index.md b/docs/index.md index 9f5d3fa15..02081c608 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. diff --git a/docs/topics/api-clients.md b/docs/topics/api-clients.md index 3fd560634..32e79d55a 100644 --- a/docs/topics/api-clients.md +++ b/docs/topics/api-clients.md @@ -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. diff --git a/docs/topics/documenting-your-api.md b/docs/topics/documenting-your-api.md index 7eab08ecf..ee1140fa9 100644 --- a/docs/topics/documenting-your-api.md +++ b/docs/topics/documenting-your-api.md @@ -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)) ] diff --git a/rest_framework/templates/rest_framework/docs/error.html b/rest_framework/templates/rest_framework/docs/error.html index ecdb67830..6c4246ce4 100644 --- a/rest_framework/templates/rest_framework/docs/error.html +++ b/rest_framework/templates/rest_framework/docs/error.html @@ -48,7 +48,7 @@ being applied unexpectedly?

when including the docs urls:

-   url(r'^docs/', include_docs_urls(title='Your API',
+   re_path(r'^docs/', include_docs_urls(title='Your API',
                                     authentication_classes=[],
                                     permission_classes=[])),