Skip to content

Commit

Permalink
Fix django.conf.url deprecation in django 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Feb 1, 2022
1 parent 1b8efb0 commit 1fb86d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ Add a URL entry to your project’s urls.py, for example:

```python
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import include

try:
from django.conf.urls import url
except ImportError:
# Django 4.0 replaced url by something else
# See https://stackoverflow.com/a/70319607/2519059
from django.urls import re_path as url

urlpatterns = [
# Your own url pattern here
Expand Down
9 changes: 8 additions & 1 deletion example_project/example_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.conf.urls import include

try:
from django.conf.urls import url
except ImportError:
# Django 4.0 replaced url by something else
# See https://stackoverflow.com/a/70319607/2519059
from django.urls import re_path as url
from django.contrib import admin

urlpatterns = [url(r"^admin/", admin.site.urls), url(r"^survey/", include("survey.urls"))]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
LONG_DESCRIPTION = f.read()

DEPENDENCIES = [
"django>=2.2,<4",
"django>=2.2",
"django-bootstrap-form>=3.4",
"django-tastypie>=0.14.2",
"django-registration>=3.0",
Expand Down
7 changes: 6 additions & 1 deletion survey/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.conf.urls import url
try:
from django.conf.urls import url
except ImportError:
# Django 4.0 replaced url by something else
# See https://stackoverflow.com/a/70319607/2519059
from django.urls import re_path as url

from survey.views import ConfirmView, IndexView, SurveyCompleted, SurveyDetail
from survey.views.survey_result import serve_result_csv
Expand Down
9 changes: 8 additions & 1 deletion urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# pylint: disable=invalid-name

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

try:
from django.conf.urls import url
except ImportError:
# Django 4.0 replaced url by something else
# See https://stackoverflow.com/a/70319607/2519059
from django.urls import re_path as url
from django.contrib import admin
from django.shortcuts import redirect
from django.urls.base import reverse
Expand Down

0 comments on commit 1fb86d4

Please sign in to comment.