Skip to content

Commit

Permalink
Updated url()'s with path() and re_path() (encode#7492)
Browse files Browse the repository at this point in the history
  • Loading branch information
saichenko authored and sigvef committed Dec 3, 2022
1 parent 56f7ec4 commit 92f3626
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
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, 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 = re_path(r'^$', view, name=self.root_view_name)
urls.append(root_url)

if self.include_format_suffixes:
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
6 changes: 3 additions & 3 deletions rest_framework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
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'),
]

0 comments on commit 92f3626

Please sign in to comment.