Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*.db
*~
.*
*.py.bak


/site/
/htmlcov/
Expand Down
4 changes: 2 additions & 2 deletions docs/api-guide/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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)
path('api-token-auth/', views.obtain_auth_token)
]

Note that the URL part of the pattern can be whatever you want to use.
Expand Down Expand Up @@ -238,7 +238,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())
path('api-token-auth/', CustomAuthToken.as_view())
]


Expand Down
2 changes: 1 addition & 1 deletion docs/api-guide/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Another style of filtering might involve restricting the queryset based on some

For example if your URL config contained an entry like this:

url('^purchases/(?P<username>.+)/$', PurchaseList.as_view()),
re_path('^purchases/(?P<username>.+)/$', PurchaseList.as_view()),

You could then write a view that returned a purchase queryset filtered by the username portion of the URL:

Expand Down
6 changes: 3 additions & 3 deletions docs/api-guide/format-suffixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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)
path('', views.apt_root),
path('comments/', views.comment_list),
path('comments/<int:pk>/', views.comment_detail)
]

urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])
Expand Down
2 changes: 1 addition & 1 deletion docs/api-guide/generic-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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')
path('users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')

---

Expand Down
2 changes: 1 addition & 1 deletion docs/api-guide/parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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())
]

---
Expand Down
14 changes: 7 additions & 7 deletions docs/api-guide/routers.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,30 @@ 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()),
path('forgot-password/', ForgotPasswordFormView.as_view()),
]

urlpatterns += router.urls

Alternatively you can use Django's `include` function, like so...

urlpatterns = [
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
url(r'^', include(router.urls)),
path('forgot-password', ForgotPasswordFormView.as_view()),
path('', 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'))),
path('forgot-password/', ForgotPasswordFormView.as_view()),
path('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')),
path('forgot-password/', ForgotPasswordFormView.as_view()),
path('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.
Expand Down
2 changes: 1 addition & 1 deletion docs/api-guide/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The `get_schema_view()` helper takes the following keyword arguments:
only want the `myproject.api` urls to be exposed in the schema:

schema_url_patterns = [
url(r'^api/', include('myproject.api.urls')),
path('api/', include('myproject.api.urls')),
]

schema_view = get_schema_view(
Expand Down
6 changes: 3 additions & 3 deletions docs/community/3.5-announcement.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ schema_view = get_schema_view(
)

urlpatterns = [
url(r'^swagger/$', schema_view),
path('swagger/', schema_view),
...
]
```
Expand Down Expand Up @@ -198,8 +198,8 @@ Make sure to include the view before your router urls. For example:
schema_view = get_schema_view(title='Example API')

urlpatterns = [
url('^$', schema_view),
url(r'^', include(router.urls)),
path('', schema_view),
path('', include(router.urls)),
]

### Schema path representations
Expand Down
2 changes: 1 addition & 1 deletion docs/community/3.6-announcement.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
path('docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
]

Once installed you should see something a little like this:
Expand Down
3 changes: 2 additions & 1 deletion docs/community/3.9-announcement.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Here's an example of adding an OpenAPI schema to the URL conf:
```python
from rest_framework.schemas import get_schema_view
from rest_framework.renderers import JSONOpenAPIRenderer
from django.urls import path

schema_view = get_schema_view(
title='Server Monitoring API',
Expand All @@ -70,7 +71,7 @@ schema_view = get_schema_view(
)

urlpatterns = [
url('^schema.json$', schema_view),
path('schema.json', schema_view),
...
]
```
Expand Down
4 changes: 2 additions & 2 deletions docs/coreapi/from-documenting-your-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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'))
path('docs/', include_docs_urls(title='My API title'))
]

This will include two different views:
Expand All @@ -41,7 +41,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))
path('docs/', include_docs_urls(title='My API title', public=False))
]


Expand Down
7 changes: 4 additions & 3 deletions docs/coreapi/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ To add a dynamically generated schema view to your API, use `get_schema_view`.

```python
from rest_framework.schemas import get_schema_view
from django.urls import path

schema_view = get_schema_view(title="Example API")

urlpatterns = [
url('^schema$', schema_view),
path('schema', schema_view),
...
]
```
Expand Down Expand Up @@ -292,7 +293,7 @@ The simplest way to include a schema in your project is to use the
schema_view = get_schema_view(title="Server Monitoring API")

urlpatterns = [
url('^$', schema_view),
path('', schema_view),
...
]

Expand Down Expand Up @@ -358,7 +359,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')),
path('api/', include('myproject.api.urls')),
]

schema_view = get_schema_view(
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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'))
path('api-auth/', include('rest_framework.urls'))
]

Note that the URL path can be whatever you want.
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/api-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'), name='api-docs'),
path('docs/', include_docs_urls(title='My API service'), name='api-docs'),
]

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.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/4-authentication-and-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ We can add a login view for use with the browsable API, by editing the URLconf i

Add the following import at the top of the file:

from django.conf.urls import include
from django.urls import path, include

And, at the end of the file, add a pattern to include the login and logout views for the browsable API.

Expand Down
6 changes: 3 additions & 3 deletions rest_framework/documentation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import include, path

from rest_framework.renderers import (
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
Expand Down Expand Up @@ -82,7 +82,7 @@ def include_docs_urls(
permission_classes=permission_classes,
)
urls = [
url(r'^$', docs_view, name='docs-index'),
url(r'^schema.js$', schema_js_view, name='schema-js')
path('', docs_view, name='docs-index'),
path('schema.js', schema_js_view, name='schema-js')
]
return include((urls, 'api-docs'), namespace='api-docs')
7 changes: 3 additions & 4 deletions rest_framework/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import itertools
from collections import OrderedDict, namedtuple

from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured
from django.urls import NoReverseMatch
from django.urls import NoReverseMatch, path, re_path

from rest_framework import views
from rest_framework.response import Response
Expand Down Expand Up @@ -265,7 +264,7 @@ def get_urls(self):

view = viewset.as_view(mapping, **initkwargs)
name = route.name.format(basename=basename)
ret.append(url(regex, view, name=name))
ret.append(re_path(regex, view, name=name))

return ret

Expand Down Expand Up @@ -340,7 +339,7 @@ def get_urls(self):

if self.include_root_view:
view = self.get_api_root_view(api_urls=urls)
root_url = url(r'^$', view, name=self.root_view_name)
root_url = path('', view, name=self.root_view_name)
urls.append(root_url)

if self.include_format_suffixes:
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/templates/rest_framework/docs/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3>403 Forbidden.</h3>
when including the docs urls:</p>

<pre>
url(r'^docs/', include_docs_urls(title='Your API',
path('docs/', include_docs_urls(title='Your API',
authentication_classes=[],
permission_classes=[])),
</pre>
Expand Down
7 changes: 3 additions & 4 deletions rest_framework/urlpatterns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.conf.urls import include, url
from django.urls import URLResolver, path, register_converter
from django.urls import URLResolver, include, path, re_path, register_converter
from django.urls.resolvers import RoutePattern

from rest_framework.settings import api_settings
Expand Down Expand Up @@ -52,7 +51,7 @@ def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required, suffix_r
route = str(urlpattern.pattern)
new_pattern = path(route, include((patterns, app_name), namespace), kwargs)
else:
new_pattern = url(regex, include((patterns, app_name), namespace), kwargs)
new_pattern = re_path(regex, include((patterns, app_name), namespace), kwargs)

ret.append(new_pattern)
else:
Expand All @@ -72,7 +71,7 @@ def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required, suffix_r
route = str(urlpattern.pattern).rstrip('$').rstrip('/') + suffix_route
new_pattern = path(route, view, kwargs, name)
else:
new_pattern = url(regex, view, kwargs, name)
new_pattern = re_path(regex, view, kwargs, name)

ret.append(new_pattern)

Expand Down
9 changes: 5 additions & 4 deletions rest_framework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

urlpatterns = [
...
url(r'^auth/', include('rest_framework.urls'))
path('auth/', include('rest_framework.urls'))
]

You should make sure your authentication settings include `SessionAuthentication`.
"""
from django.conf.urls import url
from django.contrib.auth import views
from django.urls import path

app_name = 'rest_framework'
urlpatterns = [
url(r'^login/$', views.LoginView.as_view(template_name='rest_framework/login.html'), name='login'),
url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
path('login/', views.LoginView.as_view(
template_name='rest_framework/login.html'), name='login'),
path('logout/', views.LogoutView.as_view(), name='logout'),
]
12 changes: 6 additions & 6 deletions rest_framework/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class URLPathVersioning(BaseVersioning):
An example URL conf for two views that accept two different versions.

urlpatterns = [
url(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
url(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
re_path(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
re_path(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
]

GET /1.0/something/ HTTP/1.1
Expand Down Expand Up @@ -99,14 +99,14 @@ class NamespaceVersioning(BaseVersioning):

# users/urls.py
urlpatterns = [
url(r'^/users/$', users_list, name='users-list'),
url(r'^/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
path('/users/', users_list, name='users-list'),
path('/users/<int:pk>/', users_detail, name='users-detail')
]

# urls.py
urlpatterns = [
url(r'^v1/', include('users.urls', namespace='v1')),
url(r'^v2/', include('users.urls', namespace='v2'))
path('v1/', include('users.urls', namespace='v1')),
path('v2/', include('users.urls', namespace='v2'))
]

GET /1.0/something/ HTTP/1.1
Expand Down
Loading