From cb8fe063bb6fb870951243cb512db5f29faf8611 Mon Sep 17 00:00:00 2001 From: Meteor0id <34976212+Meteor0id@users.noreply.github.com> Date: Sat, 14 Jul 2018 00:08:21 +0200 Subject: [PATCH] depriciate url() for alias re_path() --- docs/advanced_topics/i18n/index.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/advanced_topics/i18n/index.rst b/docs/advanced_topics/i18n/index.rst index a2351e5283..6b2758ea5f 100644 --- a/docs/advanced_topics/i18n/index.rst +++ b/docs/advanced_topics/i18n/index.rst @@ -82,7 +82,7 @@ This feature is enabled through the project's root URL configuration. Just put t # mysite/urls.py - from django.conf.urls import include, url + from django.conf.urls import include, re_path from django.conf.urls.i18n import i18n_patterns from django.conf import settings from django.contrib import admin @@ -93,21 +93,26 @@ This feature is enabled through the project's root URL configuration. Just put t from search import views as search_views urlpatterns = [ - url(r'^django-admin/', include(admin.site.urls)), + re_path(r'^django-admin/', include(admin.site.urls)), - url(r'^admin/', include(wagtailadmin_urls)), - url(r'^documents/', include(wagtaildocs_urls)), + re_path(r'^admin/', include(wagtailadmin_urls)), + re_path(r'^documents/', include(wagtaildocs_urls)), ] urlpatterns += i18n_patterns( # These URLs will have // appended to the beginning - url(r'^search/$', search_views.search, name='search'), + re_path(r'^search/$', search_views.search, name='search'), - url(r'', include(wagtail_urls)), + re_path(r'', include(wagtail_urls)), ) +.. important:: + + The example above assumes you are using Django version 2.0 or later. If you are using a Django version earlier than 2.0, you should rename all occurrences of re_path() to url(). For example: ``from django.conf.urls import include, url`` instead of ``from django.conf.urls import include, re_path`` and ``url(r'^django-admin/', include(admin.site.urls)),`` instead of ``re_path(r'^django-admin/', include(admin.site.urls)),``. + (`read more `_). + You can implement switching between languages by changing the part at the beginning of the URL. As each language has its own URL, it also works well with just about any caching setup.