|
1 | 1 | from django.urls import path, re_path |
2 | 2 |
|
3 | | -# This version 1.x way of defining urls is deprecated in Django 3.1, but still works |
4 | | -from django.conf.urls import url |
5 | | - |
6 | 3 | from . import views |
7 | 4 |
|
8 | 5 | urlpatterns = [ |
|
11 | 8 | # inline expectation tests (which thinks the `$` would mark the beginning of a new |
12 | 9 | # line) |
13 | 10 | re_path(r"^ba[rz]/", views.bar_baz), # $routeSetup="^ba[rz]/" |
14 | | - url(r"^deprecated/", views.deprecated), # $routeSetup="^deprecated/" |
15 | 11 |
|
16 | 12 | path("basic-view-handler/", views.MyBasicViewHandler.as_view()), # $routeSetup="basic-view-handler/" |
17 | 13 | path("custom-inheritance-view-handler/", views.MyViewHandlerWithCustomInheritance.as_view()), # $routeSetup="custom-inheritance-view-handler/" |
18 | 14 |
|
19 | 15 | path("CustomRedirectView/<foo>", views.CustomRedirectView.as_view()), # $routeSetup="CustomRedirectView/<foo>" |
20 | 16 | path("CustomRedirectView2/<foo>", views.CustomRedirectView2.as_view()), # $routeSetup="CustomRedirectView2/<foo>" |
21 | 17 | ] |
| 18 | + |
| 19 | +from django import __version__ as django_version |
| 20 | + |
| 21 | +if django_version[0] == "3": |
| 22 | + # This version 1.x way of defining urls is deprecated in Django 3.1, but still works. |
| 23 | + # However, it is removed in Django 4.0, so we need this guard to make our code runnable |
| 24 | + from django.conf.urls import url |
| 25 | + |
| 26 | + old_urlpatterns = urlpatterns |
| 27 | + |
| 28 | + # we need this assignment to get our logic working... maybe it should be more |
| 29 | + # sophisticated? |
| 30 | + urlpatterns = [ |
| 31 | + url(r"^deprecated/", views.deprecated), # $routeSetup="^deprecated/" |
| 32 | + ] |
| 33 | + |
| 34 | + urlpatterns += old_urlpatterns |
0 commit comments